Multiple actix-web client requests - expected struct actix_web::Error found ()

I have this code:

extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures; // 0.1.25
extern crate tokio; // 0.1.17
use futures::future::ok as fut_ok;
use futures::Future;
use tokio::runtime::Builder;

use std::sync::{Arc, Mutex};
extern crate serde_json;

type Error = ();

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error>> {
    let f = std::fs::read_to_string("auth_token").unwrap();
    let token = f.trim();
    use actix_web::{client, HttpMessage};
    use std::time::Duration;
    Box::new(
        client::ClientRequest::get(
            "https://jsonplaceholder.typicode.com/todos/".to_owned() + &val.to_string(),
        )
        .header(
            actix_web::http::header::AUTHORIZATION,
            "Bearer ".to_owned() + token,
        )
        .finish()
        .unwrap()
        .send()
        .timeout(Duration::from_secs(30))
        .map_err(actix_web::error::Error::from) // <- convert SendRequestError to an Error
        .and_then(|resp| {
            resp.body().limit(67_108_864).from_err().and_then(|body| {
                let resp: serde_json::Value = serde_json::from_slice(&body).unwrap();
                fut_ok(resp)
            })
        }),
    )
}

fn main() {
    let num_workers = 8;

    let mut core = Builder::new().core_threads(num_workers).build().unwrap();

    let results = Arc::new(Mutex::new(Vec::new()));
    for n in 1..100 {
        let res = results.clone();
        core.spawn(questions_data(n).map(move |n| {
            res.lock().unwrap().push(n);
        }));
    }
    core.shutdown_on_idle().wait().unwrap();
    let data = results.lock().unwrap();
    println!("{:?}", *data);
}

And my dependencies:

[dependencies]
futures = "0.1.25"
tokio-core = "0.1.17"
futures-util = "0.2.1"
tokio = "0.1.11"
rand = "0.6.0"
actix-web = "0.7.14"
actix = "0.7.6"
env_logger = "0.6.0"
serde_json = "1.0.33"

I get error when I cargo run it:

error[E0271]: type mismatch resolving `<std::boxed::Box<futures::Map<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:52:51: 54:10 res:_]>> as futures::Future>::Error == ()`
  --> src/main.rs:52:14
   |
52 |         core.spawn(Box::new(questions_data(n).map(move |n| {
   |              ^^^^^ expected struct `actix_web::Error`, found ()
   |
   = note: expected type `actix_web::Error`
              found type `()`

error[E0277]: `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
  --> src/main.rs:52:14
   |
52 |         core.spawn(Box::new(questions_data(n).map(move |n| {
   |              ^^^^^ `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `futures::Map<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:52:51: 54:10 res:_]>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<futures::Map<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:52:51: 54:10 res:_]>>`
   = note: required because it appears within the type `std::boxed::Box<futures::Map<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:52:51: 54:10 res:_]>>`

Similar code, without running actix-web client, works https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=e81185a73fcb40a3426875573c78accd

Also on so https://stackoverflow.com/questions/53338900/multiple-actix-web-client-requests-expected-struct-actix-weberror-found

EDIT:

Maybe something like map_err(|_| ()) but don’t know how to apply that:

Yup, something like:

core.spawn(questions_data(n).map_err(|e| println!("Error: {}", e)).map(move |n| {
            res.lock().unwrap().push(n);
        }));

Your “similar” code isn’t really similar because you have type Error = (), which already matches what core.spawn() wants (i.e. Error = ()).

Thank you for that.

But now I have another error:

`dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely

I saw something like this, and changed mu function to:

fn questions_data(
       val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error> + Send> {

But now I got another error:

(dyn futures::Future<Item=bytes::bytes::Bytes, Error=actix_web::error::PayloadError> + 'static)` cannot be sent between threads safely

For that you need to indicate that the future is Send (because it’s erased via a trait object, compiler cannot infer that on its own, like it can with concrete types):

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error> + Send>

Note the + Send part in the return type. I didn’t actually spot check your future there to make sure it’s truly Send, but if it’s not, the compiler will tell you about it (part of its beauty :slight_smile:).

Yes, I did that. But I was getting error about static like above.

Then I tried also this:

    fn questions_data(
        val: i32,
    ) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error> + Send>
    where
        serde_json::Value: 'static + Send,

But then I got this error:

29 | /     Box::new(
30 | |         client::ClientRequest::get(
31 | |             "https://jsonplaceholder.typicode.com/todos/1".to_owned() + &val.to_string(),
32 | |         )
...  |
47 | |         }),
48 | |     )
   | |_____^ `(dyn futures::Stream<Error=actix_web::Error, Item=bytes::bytes::Bytes> + 'static)` cannot be sent between threads safely

The issue is probably that SendRequest is !Send (https://docs.rs/actix-web/0.7.14/actix_web/client/struct.SendRequest.html#impl-Send). Are you purposely trying to use the multi-threaded tokio runtime?

Not purposely. I just need to make a couple of requests. Probably using actix-web client.

Then consider using https://docs.rs/tokio/0.1.12/tokio/runtime/current_thread/index.html, which doesn’t have the Send requirement.

Still the same error:

extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures; // 0.1.25
extern crate rand;
extern crate tokio; // 0.1.17
use futures::future::ok as fut_ok;
use futures::Future;
use futures::Stream;

use std::sync::{Arc, Mutex};
extern crate serde_json;

use std::thread;
use tokio::prelude::*;
use tokio::runtime::current_thread::Runtime;

type Error = ();

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error> + Send>
where
    serde_json::Value: 'static + Send,
{
    let f = std::fs::read_to_string("auth_token").unwrap();
    let token = f.trim();
    use actix_web::{client, HttpMessage};
    use std::time::Duration;
    Box::new(
        client::ClientRequest::get(
            "https://jsonplaceholder.typicode.com/todos/1".to_owned() + &val.to_string(),
        )
        .header(
            actix_web::http::header::AUTHORIZATION,
            "Bearer ".to_owned() + token,
        )
        .finish()
        .unwrap()
        .send()
        .timeout(Duration::from_secs(30))
        .map_err(actix_web::error::Error::from) // <- convert SendRequestError to an Error
        .and_then(|resp| {
            resp.body().limit(67_108_864).from_err().and_then(|body| {
                let resp: serde_json::Value = serde_json::from_slice(&body).unwrap();
                fut_ok(resp)
            })
        }),
    )
}

fn main() {
    let mut runtime = Runtime::new().unwrap();
    let handle = runtime.handle();

    let results: Arc<Mutex<Vec<serde_json::Value>>> = Arc::new(Mutex::new(Vec::new()));
    for n in 1..100 {
        let res = results.clone();
        thread::spawn(move || {
            handle.spawn(
                questions_data(n)
                    .map_err(|e| println!("Error: {}", e))
                    .map(move |n| {
                        res.lock().unwrap().push(n);
                    }),
            );
        })
        .join()
        .unwrap();
    }

    runtime.run().unwrap();

    let data = results.lock().unwrap();
    println!("{:?}", *data);
}

And error:

error[E0277]: `(dyn futures::Future<Item=bytes::bytes::Bytes, Error=actix_web::error::PayloadError> + 'static)` cannot be sent between threads safely
  --> src/main.rs:27:5
   |
27 | /     Box::new(
28 | |         client::ClientRequest::get(
29 | |             "https://jsonplaceholder.typicode.com/todos/1".to_owned() + &val.to_string(),
30 | |         )
...  |
45 | |         }),
46 | |     )
   | |_____^ `(dyn futures::Future<Item=bytes::bytes::Bytes, Error=actix_web::error::PayloadError> + 'static)` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `(dyn futures::Future<Item=bytes::bytes::Bytes, Error=actix_web::error::PayloadError> + 'static)`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<(dyn futures::Future<Item=bytes::bytes::Bytes, Error=actix_web::error::PayloadError> + 'static)>`
   = note: required because it appears within the type `std::boxed::Box<(dyn futures::Future<Item=bytes::bytes::Bytes, Error=actix_web::error::PayloadError> + 'static)>`
   = note: required because it appears within the type `std::option::Option<std::boxed::Box<(dyn futures::Future<Item=bytes::bytes::Bytes, Error=actix_web::error::PayloadError> + 'static)>>`
   = note: required because it appears within the type `actix_web::dev::MessageBody<actix_web::client::ClientResponse>`
   = note: required because it appears within the type `futures::future::FromErr<actix_web::dev::MessageBody<actix_web::client::ClientResponse>, actix_web::Error>`
   = note: required because it appears within the type `futures::future::chain::Chain<futures::future::FromErr<actix_web::dev::MessageBody<actix_web::client::ClientResponse>, actix_web::Error>, futures::FutureResult<serde_json::Value, actix_web::Error>, [closure@src/main.rs:41:63: 44:14]>`
   = note: required because it appears within the type `futures::AndThen<futures::future::FromErr<actix_web::dev::MessageBody<actix_web::client::ClientResponse>, actix_web::Error>, futures::FutureResult<serde_json::Value, actix_web::Error>, [closure@src/main.rs:41:63: 44:14]>`
   = note: required because it appears within the type `futures::future::chain::Chain<futures::MapErr<actix_web::client::SendRequest, fn(actix_web::client::SendRequestError) -> actix_web::Error {<actix_web::Error as std::convert::From<actix_web::client::SendRequestError>>::from}>, futures::AndThen<futures::future::FromErr<actix_web::dev::MessageBody<actix_web::client::ClientResponse>, actix_web::Error>, futures::FutureResult<serde_json::Value, actix_web::Error>, [closure@src/main.rs:41:63: 44:14]>, [closure@src/main.rs:40:19: 45:10]>`
   = note: required because it appears within the type `futures::AndThen<futures::MapErr<actix_web::client::SendRequest, fn(actix_web::client::SendRequestError) -> actix_web::Error {<actix_web::Error as std::convert::From<actix_web::client::SendRequestError>>::from}>, futures::AndThen<futures::future::FromErr<actix_web::dev::MessageBody<actix_web::client::ClientResponse>, actix_web::Error>, futures::FutureResult<serde_json::Value, actix_web::Error>, [closure@src/main.rs:41:63: 44:14]>, [closure@src/main.rs:40:19: 45:10]>`
   = note: required for the cast to the object type `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error> + std::marker::Send`

But now you need to remove the Send requirement from questions_data() return type :slight_smile: (and drop the serde_json::Value bounds as well).

I also checked this variant :confused:

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error>> {

But that get me to the previous error:

error[E0277]: `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
  --> src/main.rs:57:20
   |
57 |             handle.spawn(
   |                    ^^^^^ `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `futures::MapErr<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:59:30: 59:58]>`
   = note: required because it appears within the type `futures::Map<futures::MapErr<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:59:30: 59:58]>, [closure@src/main.rs:60:26: 62:22 res:_]>`

Why are you trying to spawn() from different threads? That would, in turn, require the Future to be Send because the handle is going to move it back to the thread running the reactor.

You probably just want to Runtime::spawn() off the main/current thread. And you then don’t need Arc<Mutex<...>> - it can be replaced with Rc<RefCell<...>> since it’s all single threaded within the reactor.

Still error:

extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures; // 0.1.25
extern crate rand;
extern crate tokio; // 0.1.17
use futures::future::ok as fut_ok;
use futures::Future;
use futures::Stream;

extern crate serde_json;

use tokio::prelude::*;
use tokio::runtime::current_thread::Runtime;

use std::cell::RefCell;
use std::rc::Rc;

type Error = ();

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error>> {
    let f = std::fs::read_to_string("auth_token").unwrap();
    let token = f.trim();
    use actix_web::{client, HttpMessage};
    use std::time::Duration;
    Box::new(
        client::ClientRequest::get(
            "https://jsonplaceholder.typicode.com/todos/1".to_owned() + &val.to_string(),
        )
        .header(
            actix_web::http::header::AUTHORIZATION,
            "Bearer ".to_owned() + token,
        )
        .finish()
        .unwrap()
        .send()
        .timeout(Duration::from_secs(30))
        .map_err(actix_web::error::Error::from) // <- convert SendRequestError to an Error
        .and_then(|resp| {
            resp.body().limit(67_108_864).from_err().and_then(|body| {
                let resp: serde_json::Value = serde_json::from_slice(&body).unwrap();
                fut_ok(resp)
            })
        }),
    )
}

fn main() {
    let mut runtime = Runtime::new().unwrap();
    let handle = runtime.handle();

    let results: Rc<RefCell<Vec<serde_json::Value>>> = Rc::new(RefCell::new(Vec::new()));
    for n in 1..100 {
        let res = results.clone();
        runtime
            .spawn(move || {
                handle.spawn(questions_data(n).map_err(|e| println!("Error: {}", e)).map(
                    move |n| {
                        res.borrow_mut().push(n);
                    },
                ));
            })
            .join()
            .unwrap();
    }

    runtime.run().unwrap();

    println!("{:?}", results.borrow().last());
}

And error:

error[E0277]: `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
  --> src/main.rs:59:24
   |
59 |                 handle.spawn(questions_data(n).map_err(|e| println!("Error: {}", e)).map(
   |                        ^^^^^ `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `futures::MapErr<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:59:56: 59:84]>`
   = note: required because it appears within the type `futures::Map<futures::MapErr<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:59:56: 59:84]>, [closure@src/main.rs:60:21: 62:22 res:_]>`

error[E0599]: no method named `join` found for type `&mut tokio::runtime::current_thread::Runtime` in the current scope
  --> src/main.rs:65:14
   |
65 |             .join()
   |              ^^^^
   |
   = note: the method `join` exists but the following trait bounds were not satisfied:
           `&mut tokio::runtime::current_thread::Runtime : futures::Future`
           `&mut &mut tokio::runtime::current_thread::Runtime : futures::Future`
           `&mut tokio::runtime::current_thread::Runtime : futures::Future`

error[E0277]: the trait bound `[closure@src/main.rs:58:20: 64:14 handle:_, n:_, res:_]: futures::Future` is not satisfied
  --> src/main.rs:58:14
   |
58 |             .spawn(move || {
   |              ^^^^^ the trait `futures::Future` is not implemented for `[closure@src/main.rs:58:20: 64:14 handle:_, n:_, res:_]`

You’re still using Handle::spawn(), which as mentioned you shouldn’t - either use Runtime::spawn() or tokio::runtime::current_thread::spawn().

Is that ok?

extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures; // 0.1.25
extern crate tokio; // 0.1.17
use futures::future::ok as fut_ok;
use futures::Future;
use futures::Stream;

extern crate serde_json;

use std::cell::RefCell;
use std::rc::Rc;
use tokio::runtime::Runtime;

type Error = ();

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error>> {
    let f = std::fs::read_to_string("auth_token").unwrap();
    let token = f.trim();
    use actix_web::{client, HttpMessage};
    use std::time::Duration;
    Box::new(
        client::ClientRequest::get(
            "https://jsonplaceholder.typicode.com/todos/1".to_owned() + &val.to_string(),
        )
        .header(
            actix_web::http::header::AUTHORIZATION,
            "Bearer ".to_owned() + token,
        )
        .finish()
        .unwrap()
        .send()
        .timeout(Duration::from_secs(30))
        .map_err(actix_web::error::Error::from) // <- convert SendRequestError to an Error
        .and_then(|resp| {
            resp.body().limit(67_108_864).from_err().and_then(|body| {
                let resp: serde_json::Value = serde_json::from_slice(&body).unwrap();
                fut_ok(resp)
            })
        }),
    )
}

fn main() {
    let results: Rc<RefCell<Vec<serde_json::Value>>> = Rc::new(RefCell::new(Vec::new()));
    let mut rt = Runtime::new().unwrap();
    for n in 1..100 {
        let res = results.clone();
        rt.spawn(
            questions_data(n)
                .map_err(|e| println!("Error: {}", e))
                .map(move |n| {
                    res.borrow_mut().push(n);
                }),
        );
    }
    println!("{:?}", results.borrow().last());
}

Probably I do something wrong because I got this error again:

error[E0277]: `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
  --> src/main.rs:52:12
   |
52 |         rt.spawn(
   |            ^^^^^ `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>` cannot be sent between threads safely
   |
   = help: the trait `std::marker::Send` is not implemented for `dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>`
   = note: required because it appears within the type `futures::MapErr<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:54:26: 54:54]>`
   = note: required because it appears within the type `futures::Map<futures::MapErr<std::boxed::Box<dyn futures::Future<Item=serde_json::Value, Error=actix_web::Error>>, [closure@src/main.rs:54:26: 54:54]>, [closure@src/main.rs:55:22: 57:18 res:_]>`

Need to use Runtime from the current_thread module: https://docs.rs/tokio/0.1.12/tokio/runtime/current_thread/struct.Runtime.html

For better or worse, there’re lots of types with the same name but different modules in tokio, and thus with different APIs.

It finally compiles :slight_smile: Thanks.

extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures; // 0.1.25
extern crate tokio; // 0.1.17
use futures::future::ok as fut_ok;
use futures::Future;

extern crate serde_json;

use std::cell::RefCell;
use std::rc::Rc;
use tokio::runtime::current_thread::Runtime;

type Error = ();

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error>> {
    use actix_web::{client, HttpMessage};
    use std::time::Duration;
    Box::new(
        client::ClientRequest::get(
            "https://jsonplaceholder.typicode.com/todos/1".to_owned() + &val.to_string(),
        )
        .finish()
        .unwrap()
        .send()
        .timeout(Duration::from_secs(30))
        .map_err(actix_web::error::Error::from) // <- convert SendRequestError to an Error
        .and_then(|resp| {
            resp.body().limit(67_108_864).from_err().and_then(|body| {
                let resp: serde_json::Value = serde_json::from_slice(&body).unwrap();
                fut_ok(resp)
            })
        }),
    )
}

fn main() {
    let results: Rc<RefCell<Vec<serde_json::Value>>> = Rc::new(RefCell::new(Vec::new()));
    let mut rt = Runtime::new().unwrap();
    for n in 1..100 {
        let res = results.clone();
        rt.spawn(
            questions_data(n)
                .map_err(|e| println!("Error: {}", e))
                .map(move |n| {
                    println!("n: {:?}", n);
                    res.borrow_mut().push(n);
                }),
        );
    }
    println!("{:?}", results.borrow().last());
}

Though it looks like it does not run those requests:

$ cargo run
...
None

You should insert a call to https://docs.rs/tokio/0.1.12/tokio/runtime/current_thread/struct.Runtime.html#method.run at the end so that you block until tokio has executed all those spawned futures.

Probably I am doing something wrong:

extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate futures; // 0.1.25
extern crate tokio; // 0.1.17
use futures::future::ok as fut_ok;
use futures::Future;

extern crate serde_json;

use std::cell::RefCell;
use std::rc::Rc;
use tokio::runtime::current_thread::Runtime;

type Error = ();

fn questions_data(
    val: i32,
) -> Box<Future<Item = serde_json::Value, Error = actix_web::error::Error>> {
    use actix_web::{client, HttpMessage};
    use std::time::Duration;
    Box::new(
        client::ClientRequest::get(
            "https://jsonplaceholder.typicode.com/todos/1".to_owned() + &val.to_string(),
        )
        .finish()
        .unwrap()
        .send()
        .timeout(Duration::from_secs(30))
        .map_err(actix_web::error::Error::from) // <- convert SendRequestError to an Error
        .and_then(|resp| {
            resp.body().limit(67_108_864).from_err().and_then(|body| {
                let resp: serde_json::Value = serde_json::from_slice(&body).unwrap();
                fut_ok(resp)
            })
        }),
    )
}

fn main() {
    let results: Rc<RefCell<Vec<serde_json::Value>>> = Rc::new(RefCell::new(Vec::new()));
    let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
    runtime.run().unwrap();
    let mut rt = Runtime::new().unwrap();
    for n in 1..100 {
        let res = results.clone();
        rt.spawn(
            questions_data(n)
                .map_err(|e| println!("Error: {}", e))
                .map(move |n| {
                    println!("n: {:?}", n);
                    res.borrow_mut().push(n);
                }),
        );
    }
    rt.run();
    println!("{:?}", results.borrow().last());
}

and output:

thread 'main' panicked at 'System is not running', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/actix-0.7.6/src/system.rs:116:21

I need to start actix-web probably