From 21507d3da14928068b1eddd0de4f0c2c8a8a1d27 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 12 Apr 2019 12:26:47 -0700 Subject: [PATCH] add TestServerRuntime::run_on() method --- actix-test-server/Cargo.toml | 2 +- actix-test-server/src/lib.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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