-
Notifications
You must be signed in to change notification settings - Fork 339
Re-export task::spawn
and task::spawn_blocking
at top-level
#1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A goal we had when designing
async-std
was to create a module hierarchy which resembled the hierarchy of the stdlib - but expanding on it with async-only capabilities in certain locations. This was with the expectation that one day we might add these APIs into the stdlib itself. And at least my hope is that we may eventually enable a diff like this:You're probably in a better position to answer this, but I kind of assumed that in the stdlib we would likely want to scope the
spawn
family of functions to submodules, and likely not expose them directly fromstd
's root? Meaning that even if we create anasync_std::spawn
, we'd unlikely ever have astd::spawn
?Alternatives
I do think you're touching on an important insight here though:
spawn
ing tasks is a common operation, and making that convenient to perform seems important. I've recently been experimenting with makingspawn
a method onFuture
. This solves the same problem by not requiring any imports at all:Open questions
I've been contemplating whether we could add this to
async-std
as part ofFutureExt
, possibly even deprecatingtask::spawn
as part of it. Though there are still a few open questions with this:core::future::Future
, but this extension may only be possible onstd
? Perhaps there is something withcontexts
we could provide, or perhaps the unification ofcore
andstd
would help? But I'm not sure what the right path for the stdlib here would be.tasky
prototype of this idea has bothspawn
andspawn_local
variants of this method. This is probably worth its own blog post, butspawn_local
doesn't appear to be the right abstraction. Instead we need to find a way to define a spawn method with "the captured values from the scope can be sent to another thread, but once the future is constructed it will no longer move between threads". Much like thethread::spawn
API works. I'm not sure yet how to do this, as it seems like it needs to be implemented at theasync-task
layer.spawn_blocking
. It doesn't really make sense to define it asFutureExt::spawn_blocking
since it's only intended to be used for non-future workloads. Having aT::spawn_blocking
feels wrong too. How common is it to use this method? What is the right way to expose this functionality?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, we're unlikely to ever have a
std::spawn
, so we shouldn't make this change.In theory, we could make
spawn_blocking
take a future, since it may want to run a mix of sync and async work.But whether we do that or not, I'm not sure we want to have
spawn
as a method on futures.