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

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