def test_apply_to_function(self): async def sleep(): await asyncio.sleep(0.1) return "derp" unsync_sleep = unsync(sleep) self.assertEqual(unsync_sleep().result(), "derp")
def test_unsync_threaded_multiple(self): def non_async_work(): time.sleep(0.1) return 'faff' @unsync async def wait(_futures): return [await _future for _future in _futures] futures = [unsync(non_async_work)() for _ in range(20)] self.assertTrue(all([res == 'faff' for res in wait(futures).result()]))
def test_unsync_threaded_with_await(self): def non_async_work(): time.sleep(0.1) return 'faff' @unsync async def wait(_future): await asyncio.sleep(0.1) return await _future future = unsync(non_async_work)() self.assertEqual('faff', wait(future).result())
def test_apply_to_built_in(self): unsync_sleep = unsync(time.sleep) unsync_sleep(0.1).result()
def function_name(x: str) -> Unfuture[str]: async_method = unsync(__function_name_synced) return async_method(x)