Optionally run a coroutine when using dispatch.run_forever
#180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The behavior of
dispatch.run
changed recently. Previously it would start a Dispatch endpoint server and serve forever. It optionally accepted a function to run once the server had been started, allowing users to dispatch an initial function call. Now it requires a coroutine as input, and sets up the Dispatch endpoint server only for the lifetime of the coroutine. Once the coroutine returns,dispatch.run
returns its result after tearing down the endpoint server.Users may need the ability to debug what happened with their function calls after they returned. However, if the Dispatch endpoint exits, the CLI will exit too.
There's a
dispatch.run_forever
variant that's closer to the original behavior ofdispatch.run
. It serves the endpoint forever, however it doesn't accept a coroutine as input nor a function to run when the server has been started.This PR updates
dispatch.run_forever
to accept the same input asdispatch.run
. If a coroutine is provided, it's run when the server has been started. Unlikedispatch.run
, it doesn't return the result of the coroutine, instead keeping the server (and CLI, if applicable) running.