Exemplo n.º 1
0
    def test_await_from_result(self):
        future = Unfuture.from_value('faff')

        @unsync
        async def wait(_future):
            return await _future

        self.assertEqual('faff', wait(future).result())
Exemplo n.º 2
0
def process_cpu(task: Unfuture):
    print("Computing...")
    result: float = 0.0
    number = task.result()
    for _ in range(1, 10_000_000):
        result = math.sqrt(number**number + .01)
Exemplo n.º 3
0
async def process(task: Unfuture):
    print("process...")
    await asyncio.sleep(0.1)
    return task.result() * 2
Exemplo n.º 4
0
 def test_from_result(self):
     future = Unfuture.from_value('faff')
     self.assertEqual('faff', future.result())
Exemplo n.º 5
0
    def concurrent_future(result='faff'):
        def wait():
            time.sleep(0.1)
            return result

        return Unfuture(FutureTests.executor().submit(wait))