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

Provide futures::task::Spawn implementation #142

Closed
Nemo157 opened this issue Sep 4, 2019 · 9 comments
Closed

Provide futures::task::Spawn implementation #142

Nemo157 opened this issue Sep 4, 2019 · 9 comments
Labels
enhancement New feature or request

Comments

@Nemo157
Copy link

Nemo157 commented Sep 4, 2019

To support executor agnostic libraries it would be useful to have a handle that can be passed to them if they require the ability to spawn new tasks.

@skade
Copy link
Collaborator

skade commented Sep 5, 2019

This would make us rely on futures types in the public interface, which we don't want to do. That's not only for the Spawn type, but also all Error types and FutureObj.

A spawner is also pretty simple to write and I'd prefer frameworks to ship their own if they want to. An example for the patters library would be useful, though.

@Nemo157
Copy link
Author

Nemo157 commented Sep 5, 2019

async-std already exposes types from futures in the public interface, passing an async_std::fs::File to a function accepting impl futures::io::AsyncRead works. Spawn is currently defined in futures-core so it is positioned as even more stable than the IO traits (although there is an issue open about moving it out of there rust-lang/futures-rs#1830).

A spawner is also pretty simple to write and I'd prefer frameworks to ship their own if they want to.

A ZST spawn impl calling out to a global function is trivial to write, I just don't see why that should be repeated 100's of times across every application that wants to call into an executor-agnostic library when it can be provided by the executor. I guess someone could publish async-std-spawn and everyone can just depend on that instead.

@skade
Copy link
Collaborator

skade commented Sep 5, 2019

@Nemo157 yes, but it explicitly rules out those types from its stability guarantees.

It's precisely the open issues that make it hard for us to currently commit on these. An async-std-spawn would be perfectly great in that line of thinking, even one published and maintained by this project itself, to be clear!

@Nemo157
Copy link
Author

Nemo157 commented Sep 5, 2019

I should also say that there is also tokio::executor::{Executor, TypedExecutor} which are being used by some crates like hyper currently. So it probably makes a lot of sense to provide separate adaptor crates until there has been more experimentation and the ecosystem has stabilized a bit.

@skade
Copy link
Collaborator

skade commented Sep 5, 2019

Yes. I want to generally write down a strategy/contribution document for such things soon (tm) to bring some clarity into this.

@yoshuawuyts
Copy link
Contributor

The code for this would probably be along the lines of:

#[derive(Debug)]
struct Spawner;

impl futures::task::Spawn for Spawner {
    fn spawn_obj(&mut self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
        async_std::task::spawn(future)?; // cast the error somehow
        Ok(())
    }
}

I agree having a separate for this would be convenient. @Nemo157 is this something you would want to author?

@yoshuawuyts yoshuawuyts added the enhancement New feature or request label Sep 18, 2019
@Nemo157
Copy link
Author

Nemo157 commented Sep 18, 2019

Unfortunately I'm not using async-std enough in real projects to have the motivation to maintain a crate for that.

@yoshuawuyts
Copy link
Contributor

@Nemo157 that makes sense; thanks for the quick reply!

@yoshuawuyts
Copy link
Contributor

It doesn't seem anyone is particularly eager to implement this anytime soon. Also the Spawn trait might be removed from futures-core in the near future. I think it's okay to go ahead and close this for now.

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

No branches or pull requests

3 participants