def test_blocking_get_wait(self):

    def gen():
        when = (yield)
        self.assertAlmostEqual(0.01, when)
        (yield 0.01)
    loop = self.new_test_loop(gen)
    q = asyncio.Queue(loop=loop)
    started = asyncio.Event(loop=loop)
    finished = False

    @asyncio.coroutine
    def queue_get():
        nonlocal finished
        started.set()
        res = (yield from q.get())
        finished = True
        return res

    @asyncio.coroutine
    def queue_put():
        loop.call_later(0.01, q.put_nowait, 1)
        queue_get_task = asyncio.Task(queue_get(), loop=loop)
        (yield from started.wait())
        self.assertFalse(finished)
        res = (yield from queue_get_task)
        self.assertTrue(finished)
        return res
    res = loop.run_until_complete(queue_put())
    self.assertEqual(1, res)
    self.assertAlmostEqual(0.01, loop.time())
def test_blocking_get_wait(self):

    def gen():
        when = (yield)
        self.assertAlmostEqual(0.01, when)
        (yield 0.01)
    loop = self.new_test_loop(gen)
    q = asyncio.Queue(loop=loop)
    started = asyncio.Event(loop=loop)
    finished = False

    @asyncio.coroutine
    def queue_get():
        nonlocal finished
        started.set()
        res = (yield from q.get())
        finished = True
        return res

    @asyncio.coroutine
    def queue_put():
        loop.call_later(0.01, q.put_nowait, 1)
        queue_get_task = asyncio.Task(queue_get(), loop=loop)
        (yield from started.wait())
        self.assertFalse(finished)
        res = (yield from queue_get_task)
        self.assertTrue(finished)
        return res
    res = loop.run_until_complete(queue_put())
    self.assertEqual(1, res)
    self.assertAlmostEqual(0.01, loop.time())