-
Notifications
You must be signed in to change notification settings - Fork 340
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
[discussion] task::block_on -> thread::block_on? #289
Comments
Okay, riffing on this a bit more. Now that #299 is a thing, things have changed even more as fn task::spawn(impl Future) -> JoinHandle;
fn task::spawn_thread(impl FnOnce) -> JoinHandle; So there seems to be somewhat of a parallel here now with fn thread::spawn(impl FnOnce) -> JoinHandle;
fn thread::spawn_async(impl Future) -> JoinHandle; This creates a nice parallel I think, and nicely bridges between the two concepts. We could perhaps even take the names slightly further, and call them each other's submodule: fn task::spawn(impl Future) -> task::JoinHandle;
fn task::spawn_thread(impl FnOnce) -> task::JoinHandle;
fn thread::spawn(impl FnOnce) -> thread::JoinHandle;
fn thread::spawn_task(impl Future) -> thread:: JoinHandle; The only concern here is that |
Okay, tried to implement this and That kind of begs the question whether it still makes sense the way it's done (or whether it should have a different kind of join handle), but in general I still kind of like the direction we're proposing, even without the |
I don't think this is worth it at this time. Closing! |
Okay so this might be a terrible idea, and I'm not convinced myself -- but I think it's still worth bringing up because there might be value to it.
In #251 we're going to add
task::blocking
, but the name is kind of similar totask::block_on
. The difference between the two is that one takes a closure that will block a thread, while the other one blocks the current thread:What I'm slightly worried about is that people will not catch the difference between the two methods, and use
block_on
instead ofblocking
. And to be fair; this will probably work in most situations -- except performance will be terrible because this is not at all intended for this.So instead I'm wondering if it would perhaps make sense to move
block_on
to be part of thethread
submodule. It already has several other functions related to blocking the current thread, and this would be another one in that line.A reason why I'm kind of wondering about using the
thread
submodule is because we probably want to give people access to the threadpool to configure it, and I feelthread
may be a good option to put it (though I have no idea which knobs we'd want to allow people to turn). Which if we have that submodule anyway we may want to consider this direction also. I'm not sure though!Perhaps another way to go about this would be to make
block_on
fail if called inside of atask
context:Oh also; none of this is pressing at all, and just wanted to bring this up as something that may be interesting to consider. Thanks!
The text was updated successfully, but these errors were encountered: