Skip to content
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

Add possibility to configure the way tasks are spawned #137

Closed
tomaka opened this issue Sep 1, 2019 · 4 comments
Closed

Add possibility to configure the way tasks are spawned #137

tomaka opened this issue Sep 1, 2019 · 4 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@tomaka
Copy link

tomaka commented Sep 1, 2019

The async_std::task::Builder and async_std::task::spawn methods assume that some kind of environment is present (ie. a background thread pool) where to spawn tasks.

async-std/src/task/pool.rs

Lines 172 to 192 in 532c73c

static ref QUEUE: Sender<Job> = {
let (sender, receiver) = unbounded::<Job>();
for _ in 0..num_cpus::get().max(1) {
let receiver = receiver.clone();
thread::Builder::new()
.name("async-task-driver".to_string())
.spawn(|| {
TAG.with(|tag| {
for job in receiver {
tag.set(job.tag());
abort_on_panic(|| job.run());
tag.set(ptr::null());
}
});
})
.expect("cannot start a thread driving tasks");
}
sender
};

Crates that provide some sort of hidden environment generally provide a way to configure how it works. Example of what I mean:

Similarly, I think async_std should provide some sort of set_task_spawner function that allows configuring how that works.

The use-case I have in mind is the browser environment, where you want to drive tasks by using spawn_local (which is implemented using setTimeout).

@yoshuawuyts
Copy link
Contributor

yoshuawuyts commented Sep 1, 2019

@tomaka on phone right now — but would perhaps an acceptable short-term solution to your issue be to allow async-std to work in the browser? Specifically task::spawn.

@tomaka
Copy link
Author

tomaka commented Sep 1, 2019

short-term solution

It's not urgent at all!
My browser experiments work by merging everything into a single future. I don't spawn anything in the background at the moment.

@sdroege
Copy link

sdroege commented Sep 2, 2019

See also #79, which is kind of related but broader.

@yoshuawuyts
Copy link
Contributor

As this is mostly already covered by #79, I'm going to go ahead and close this issue. We should continue to gather input on what folks want to configure and report it back in #79.

Thanks all!

@yoshuawuyts yoshuawuyts added duplicate This issue or pull request already exists enhancement New feature or request labels Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants