Skip to content

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