Skip to content

pending time-delayed events awaitable for Python asyncio

License

Notifications You must be signed in to change notification settings

koodaamo/pending

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pending events awaitable for asyncio

Instantiate a Pending awaitable, register events scheduled to be returned after a given number of seconds, and then await.

Once the first one (with smallest scheduling delay) is returned, re-await to get the next one, and so on. Optionally cancel or postpone (reschedule) scheduled events.

Example of use:

>>> import asyncio
>>> from pending import Pending
>>> events = Pending()
>>> events.schedule("second", 10)
>>> events.schedule("first", 9)
>>> async def main():
...    for i in len(events):
...       evt = await events
...       print(evt)
...
>>> asyncio.run(main())
first
second

Note: the registered "event" can be any hashable object.

About

pending time-delayed events awaitable for Python asyncio

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages