Introduce some new Schedule
operation for explicit nesting.
#238
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.
This is an alternative to the proposal in #237.
It requires the following:
I have no opinion about the name right now.
The original proposal has this example code:
It would become this:
However, I think it's worse, because the error of the missing event loop is delayed until some processing is already done. It also begs the question, why such an error is useful. If the expectation is that method can run concurrently, just make it so (see "Using Outer
Sync
Instead", below).The alternative design avoids this:
It's also going to be a little less efficient to look up the parent context on every iteration, and it also gives you less control (e.g. providing an explicit semaphore to
parent:
).By the way, it should be noted, that
Fiber.schedule
is very similar to the desired functionality:It should also be noted that my original proposal was
Fiber{}
rather thanFiber.schedule{}
. In the original proposal, it could be used like this:Using Outer
Sync
InsteadThe point of the
Async
interface is to avoid the user having to be aware of the parent concurrency, however, I do accept there are a few sharp edge cases. For example, if you are expectingAsync
to run in conjunction with other tasks.For the purpose of this library, I'm not very enthusiastic about breaking backwards compatibility, but I'm okay to introduce new features if they help the code become more expressive and less error-prone.
Contribution