Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

futures-cpupool support with boxed future #60

Closed
raviqqe opened this issue Feb 7, 2018 · 2 comments
Closed

futures-cpupool support with boxed future #60

raviqqe opened this issue Feb 7, 2018 · 2 comments

Comments

@raviqqe
Copy link
Contributor

raviqqe commented Feb 7, 2018

The code below cannot be compiled. That seems to be because Box<Future> is not Send. While #[async(boxed)] is not necessary and #[async] works well instead here, it's better to support some kind of boxed generator which is Send as they would be common in complex applications (e.g. when writing recursive functions.)

This issue may be related to #15 because the problem is caused by trait objects. I guess something like Box<G> where G: Generator fixes it. Or some way to support Box<Future + Send>?

#![feature(proc_macro, generators)]

extern crate futures_await as futures;
extern crate futures_cpupool;

use futures::prelude::*;
use futures_cpupool::*;

#[async(boxed)]
fn foo() -> Result<(), ()> {
    Ok(())
}

fn main() {
    CpuPool::new_num_cpus().spawn(foo()).wait();
}

Build log:

> cargo build
   Compiling rust-async-await-examples v0.1.0 (file:///home/raviqqe/src/github.com/raviqqe/rust-async-await-examples)
error[E0277]: the trait bound `futures::Future<Error=(), Item=()>: std::marker::Send` is not satisfied
  --> src/main.rs:15:29
   |
15 |     CpuPool::new_num_cpus().spawn(foo()).wait();
   |                             ^^^^^ `futures::Future<Error=(), Item=()>` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `futures::Future<Error=(), Item=()>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<futures::Future<Error=(), Item=()>>`
   = note: required because it appears within the type `std::boxed::Box<futures::Future<Error=(), Item=()>>`

error: aborting due to previous error

error: Could not compile `rust-async-await-examples`.

To learn more, run the command again with --verbose.
@raviqqe raviqqe changed the title futures-cpupool support of boxed future futures-cpupool support with boxed future Feb 7, 2018
@raviqqe
Copy link
Contributor Author

raviqqe commented Feb 7, 2018

I made an experimental branch just with Box<Future + Send + Sync> and it works well with my project. However, they should be optional.

@alexcrichton
Copy link
Owner

Thanks! Want to add it upstream? I imagine we could do something like #[async(boxed_send)] or something like that.

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

No branches or pull requests

2 participants