diff --git a/actix-test-server/Cargo.toml b/actix-test-server/Cargo.toml index 010ec1eb..7dae2175 100644 --- a/actix-test-server/Cargo.toml +++ b/actix-test-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-test-server" -version = "0.2.0" +version = "0.2.1" authors = ["Nikolay Kim "] description = "Actix test server" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-test-server/src/lib.rs b/actix-test-server/src/lib.rs index 49608cf6..dd7da733 100644 --- a/actix-test-server/src/lib.rs +++ b/actix-test-server/src/lib.rs @@ -6,7 +6,7 @@ use actix_rt::{Runtime, System}; use actix_server::{Server, StreamServiceFactory}; pub use actix_server_config::{Io, ServerConfig}; -use futures::Future; +use futures::future::{lazy, Future, IntoFuture}; use net2::TcpBuilder; use tokio_reactor::Handle; use tokio_tcp::TcpStream; @@ -99,6 +99,15 @@ impl TestServerRuntime { self.rt.block_on(fut) } + /// Runs the provided function, with runtime enabled. + pub fn run_on(&mut self, f: F) -> Result + where + F: FnOnce() -> R, + R: IntoFuture, + { + self.rt.block_on(lazy(|| f().into_future())) + } + /// Spawn future to the current runtime pub fn spawn(&mut self, fut: F) where