# Path: paco/concurrent.py
# def safe_run(coro, return_exceptions=False):
# def collect(coro, index, results,
#             preserve_order=False,
#             return_exceptions=False):
#     def __init__(self, limit=10, loop=None, coros=None, ignore_empty=False):
#     def __len__(self):
#     def reset(self):
#     def cancel(self):
#     def on(self, event, fn):
#     def off(self, event):
#     def extend(self, *coros):
#     def add(self, coro, *args, **kw):
#     def _run_sequentially(self):
#     def _run_concurrently(self, timeout=None, return_when='ALL_COMPLETED'):
#     def _run_coro(self, task):
#     def _schedule_coro(self, task):
#     def run(self,
#             timeout=None,
#             return_when=None,
#             return_exceptions=None,
#             ignore_empty=None):
#     def is_running(self):
# class ConcurrentExecutor(object):
# 
# Path: tests/helpers.py
# @asyncio.coroutine
# def sleep_coro(timespan=0.1):
#     start = time.time()
#     yield from asyncio.sleep(timespan)
#     return time.time() - start
# 
# def run_in_loop(coro, *args, **kw):
#     loop = asyncio.get_event_loop()
#     if asyncio.iscoroutinefunction(coro) or isfunction(coro):
#         coro = coro(*args, **kw)
#     return loop.run_until_complete(coro)


import time
import pytest
import asyncio
from paco import concurrent
from .helpers import sleep_coro, run_in_loop
# -*- coding: utf-8 -*-


@asyncio.coroutine
def run_test(limit=3, times=10, timespan=0.1):
    p = concurrent(limit)
    for i in range(times):
        p.add(sleep_coro, timespan)
    return (yield from p.run())


def test_concurrent_single():
    @asyncio.coroutine
    def coro(num):
        return num * 2


# Path: paco/concurrent.py
# def safe_run(coro, return_exceptions=False):
# def collect(coro, index, results,
#             preserve_order=False,
#             return_exceptions=False):
#     def __init__(self, limit=10, loop=None, coros=None, ignore_empty=False):
#     def __len__(self):
#     def reset(self):
#     def cancel(self):
#     def on(self, event, fn):
#     def off(self, event):
#     def extend(self, *coros):
#     def add(self, coro, *args, **kw):
#     def _run_sequentially(self):
#     def _run_concurrently(self, timeout=None, return_when='ALL_COMPLETED'):
#     def _run_coro(self, task):
#     def _schedule_coro(self, task):
#     def run(self,
#             timeout=None,
#             return_when=None,
#             return_exceptions=None,
#             ignore_empty=None):
#     def is_running(self):
# class ConcurrentExecutor(object):
# 
# Path: tests/helpers.py
# @asyncio.coroutine
# def sleep_coro(timespan=0.1):
#     start = time.time()
#     yield from asyncio.sleep(timespan)
#     return time.time() - start
# 
# def run_in_loop(coro, *args, **kw):
#     loop = asyncio.get_event_loop()
#     if asyncio.iscoroutinefunction(coro) or isfunction(coro):
#         coro = coro(*args, **kw)
#     return loop.run_until_complete(coro)


# Path: tests/concurrent_test.py
import time
import pytest
import asyncio
from paco import concurrent
from .helpers import sleep_coro, run_in_loop

# -*- coding: utf-8 -*-


@asyncio.coroutine
def run_test(limit=3, times=10, timespan=0.1):
    p = concurrent(limit)
    for i in range(times):
        p.add(sleep_coro, timespan)
    return (yield from p.run())


def test_concurrent_single():
    @asyncio.coroutine
    def coro(num):
        return num * 2


    p = concurrent(10)