Skip to content

Blocking updates #299

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

Merged
merged 4 commits into from
Oct 15, 2019
Merged

Blocking updates #299

merged 4 commits into from
Oct 15, 2019

Conversation

yoshuawuyts
Copy link
Contributor

Renames task::blocking to task::spawn_blocking, and changes the input type from impl Future to impl FnOnce so that it becomes clear that this function is for non-async code only.

We received public feedback on the signature, and @stjepang and I spoke privately about the method name and agreed that it was indeed confusing with block_on also being a thing.

Because this API has changed, it means that #290 will no longer be able to be called inside task::blocking, but instead tasks should rely on thread::yield_now instead. This overall feels like a positive to me.

Thanks!

@yoshuawuyts
Copy link
Contributor Author

As per #289, we may want to consider renaming this to task::spawn_thread instead of task::spawn_blocking as to have a counterpart to thread::spawn_task.

@yoshuawuyts yoshuawuyts added this to the 0.99.10 milestone Oct 13, 2019
@ghost
Copy link

ghost commented Oct 14, 2019

Need to think about this.

I'll just throw in another idea for the signature of this function:

pub async fn asyncify<F, R>(f: F)
where
    F: FnOnce() -> R + Send + 'static,
    R: Send + 'static,
{
    blocking::spawn(f).await
}

Might also consider putting this function into the async_std::future module.

Unsure about these ideas though. Need to mull over them :)

@yoshuawuyts yoshuawuyts merged commit d46364c into master Oct 15, 2019
@yoshuawuyts yoshuawuyts deleted the blocking-updates branch October 15, 2019 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant