dispatchrun / dispatch-py

Python package to develop applications with Dispatch.
https://pypi.org/project/dispatch-py/
Apache License 2.0
54 stars 3 forks source link

Sleep directive #89

Open chriso opened 7 months ago

chriso commented 7 months ago

The local coroutine scheduler (#52) interacts with Dispatch by polling with zero or more calls. Another capability of poll is the ability to delay resumption of the coroutine(s) (using max_wait).

The scheduler could provide a sleep(duration) directive – alongside the existing call and gather directives – that puts a coroutine to sleep for the specified duration.

This could obviously be used to delay work. It could also be used with https://github.com/stealthrocket/dispatch-sdk-python/issues/88 to implement higher-level concurrency patterns. For example, await any(sleep(0), someOperation()) could be used to submit a fire-and-forget operation without blocking the coroutine, allowing it to continue on with additional work.

Pryz commented 3 months ago

I was looking at sleep and found this issue. Now that we are integrated with asyncio, I'm guessing we should somehow integrate with asyncio.sleep.

However I'm wondering if we should implement that in the Ring side to provide durable sleeps.