-
-
Save snower/c4f1d4d55281e9456daf1a66831db821 to your computer and use it in GitHub Desktop.
await_test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# 2021/9/8 | |
# create by: snower | |
import asyncio | |
from asyncio import Future | |
callback_list = [] | |
def func(callback): | |
callback_list.append(callback) | |
def func_await(): | |
future = Future() | |
def on_finish(): | |
future.set_result(None) | |
func(on_finish) | |
return future | |
async def test(): | |
print(1) | |
await func_await() | |
print(2) | |
async def run(): | |
await test() | |
await test() | |
def run_loop(): | |
while len(callback_list) != 0: | |
callback = callback_list.pop(0) | |
callback() | |
loop.call_later(0.1, run_loop) | |
loop = asyncio.get_event_loop() | |
loop.call_soon(run_loop) | |
loop.run_until_complete(run()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment