Skip to content

Instantly share code, notes, and snippets.

@snower
Created September 8, 2021 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snower/c4f1d4d55281e9456daf1a66831db821 to your computer and use it in GitHub Desktop.
Save snower/c4f1d4d55281e9456daf1a66831db821 to your computer and use it in GitHub Desktop.
await_test
# -*- 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