예제 #1
0
    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")
예제 #2
0
    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()]))
예제 #3
0
    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())
예제 #4
0
    def test_apply_to_built_in(self):
        unsync_sleep = unsync(time.sleep)

        unsync_sleep(0.1).result()
예제 #5
0
 def function_name(x: str) -> Unfuture[str]:
     async_method = unsync(__function_name_synced)
     return async_method(x)