示例#1
0
    async def main():
        promise = Promise()
        assert not promise.is_set()

        producer_task = await curio.spawn(producer(promise))

        assert 42 == await consumer(promise)
        assert promise.is_set()
示例#2
0
    async def main():
        promise = Promise()
        producer_task = await curio.spawn(exception_producer(promise))

        with pytest.raises(RuntimeError):
            await consumer(promise)

        await producer_task.join()
示例#3
0
    async def main():
        promise = Promise()
        assert not promise.is_set()
        assert repr(promise).endswith('[unset]>')

        await promise.set(42)

        assert promise.is_set()
        assert promise._data == 42
        assert promise._exception is None
        assert repr(promise).endswith('[42]>')

        promise.clear()

        assert not promise.is_set()
        assert promise._data is None
        assert promise._exception is None
        assert repr(promise).endswith('[unset]>')

        async with promise:
            raise RuntimeError()

        assert promise.is_set()
        assert promise._data is None
        assert isinstance(promise._exception, RuntimeError)
        assert repr(promise).endswith('[RuntimeError()]>')

        promise.clear()

        assert not promise.is_set()
        assert promise._data is None
        assert promise._exception is None
        assert repr(promise).endswith('[unset]>')
示例#4
0
 async def main():
     promise = Promise()
     async with promise:
         pass
     assert not promise.is_set()