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())
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)
async def process(task: Unfuture): print("process...") await asyncio.sleep(0.1) return task.result() * 2
def test_from_result(self): future = Unfuture.from_value('faff') self.assertEqual('faff', future.result())
def concurrent_future(result='faff'): def wait(): time.sleep(0.1) return result return Unfuture(FutureTests.executor().submit(wait))