Skip to content

Unable to use with tokio::spawn() ("the trait std::marker::Send is not implemented") #11

@aisrael

Description

@aisrael

Am trying to use influxdb within a Hyper/tokio request handler. Since your InfluxDB client is asynchronous, I figured it'd be a better choice (to keep everything async).

However, when I try to run the following code in my hyper service:

 let client = InfluxDbClient::new("http://localhost:8086", "test"); let write_query = InfluxDbQuery::write_query(Timestamp::NOW, "weather").add_field("temperature", 82); tokio::spawn(client.query(&write_query)); 

I promptly get:

error[E0277]: `dyn futures::future::Future<Error = influxdb::error::InfluxDbError, Item = std::string::String>` cannot be sent between threads safely --> src/arboric/mod.rs:59:5 | 59 | tokio::spawn(client.query(&write_query)); | ^^^^^^^^^^^^ `dyn futures::future::Future<Error = influxdb::error::InfluxDbError, Item = std::string::String>` cannot be sent between threads safely | = help: the trait `std::marker::Send` is not implemented for `dyn futures::future::Future<Error = influxdb::error::InfluxDbError, Item = std::string::String>` = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<dyn futures::future::Future<Error = influxdb::error::InfluxDbError, Item = std::string::String>>` = note: required because it appears within the type `std::boxed::Box<dyn futures::future::Future<Error = influxdb::error::InfluxDbError, Item = std::string::String>>` = note: required by `tokio::executor::spawn` 

Am unsure of how to proceed. Can I just fork influxdb-rust and add + Send to the return type of InfluxDbClient::query()? Is the return value even Send-able, or should I clone it?

(Pardon me if this should be something obvious, am quite a beginner still with Rust + tokio + futures.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions