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

Move spawn, spawn_with_handle into futures-util as macros #1140

Closed
MajorBreakfast opened this issue Jul 29, 2018 · 10 comments
Closed

Move spawn, spawn_with_handle into futures-util as macros #1140

MajorBreakfast opened this issue Jul 29, 2018 · 10 comments

Comments

@MajorBreakfast
Copy link
Contributor

MajorBreakfast commented Jul 29, 2018

These are currently in futures-executor/src/spawn.rs but they don't depend on anything from the futures-executor crate => they should live in futures-util because they're general purpose and similar to the kind of stuff in futures-util

@cramertj
Copy link
Member

Yeah, that sounds good! I'd also +1 spawn! and spawn_with_handle! macros for wrapping them in await!s.

@MajorBreakfast
Copy link
Contributor Author

I also favor the macro versions and would like to replace these with macro versions. However, @Nemo157 mentioned this use case once:

let handle = await!(spawn_with_handle(future).with_executor(...));

How could this work with macros?

@cramertj
Copy link
Member

You could always fall back to using await! if the macros aren't what you want, but I think the macros are good for capturing the common case.

@aajtodd
Copy link

aajtodd commented Jul 29, 2018

The documentation on spawn says that the function will spawn the given future as a task onto the default executor, maybe I'm missing something but I don't see where this happens.

@MajorBreakfast
Copy link
Contributor Author

@aajtodd You're right. It should say "the context's executor"

@MajorBreakfast
Copy link
Contributor Author

@cramertj How about providing only macros, but with an optional executor parameter?

spawn!(future);
spawn!(future, executor);

@cramertj
Copy link
Member

@MajorBreakfast if you have an executor and a future, you don't need a macro-- you can write executor.spawn_obj(Box::new(future).into()) (eventually executor.spawn(future)). I guess we'd be saving a few characters by avoiding the whole Box::new(...).into() dance, but we could do the same by providing an extension trait that delegated to spawn_obj internally (similar to the existing one for Context).

@MajorBreakfast
Copy link
Contributor Author

@cramertj You're right, the macro isn't needed for this use case. I've created an issue for ExecutorExt with an approach that I think would work. Once we have ExecutorExt, we can build easy to use spawn! and spawn_with_handle! macros around it.

@Nemo157
Copy link
Member

Nemo157 commented Jul 30, 2018

The documentation on spawn says that the function will spawn the given future as a task onto the default executor, maybe I'm missing something but I don't see where this happens.

You're right. It should say "the context's executor"

I had the same initial reaction, eventually I figured out that "the default executor" is "the current context's executor", there's nothing else for it to refer to. 👍 for clarifying this a bit more.

@MajorBreakfast MajorBreakfast changed the title Move spawn, spawn_with_handle into futures-util Move spawn, spawn_with_handle into futures-util as macros Jul 30, 2018
@MajorBreakfast
Copy link
Contributor Author

Closed by #1156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants