mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 03:42:59 +01:00
add TestServerRuntime::run_on() method
This commit is contained in:
parent
b9d8a215b4
commit
21507d3da1
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-test-server"
|
name = "actix-test-server"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix test server"
|
description = "Actix test server"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@ -6,7 +6,7 @@ use actix_rt::{Runtime, System};
|
|||||||
use actix_server::{Server, StreamServiceFactory};
|
use actix_server::{Server, StreamServiceFactory};
|
||||||
pub use actix_server_config::{Io, ServerConfig};
|
pub use actix_server_config::{Io, ServerConfig};
|
||||||
|
|
||||||
use futures::Future;
|
use futures::future::{lazy, Future, IntoFuture};
|
||||||
use net2::TcpBuilder;
|
use net2::TcpBuilder;
|
||||||
use tokio_reactor::Handle;
|
use tokio_reactor::Handle;
|
||||||
use tokio_tcp::TcpStream;
|
use tokio_tcp::TcpStream;
|
||||||
@ -99,6 +99,15 @@ impl TestServerRuntime {
|
|||||||
self.rt.block_on(fut)
|
self.rt.block_on(fut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs the provided function, with runtime enabled.
|
||||||
|
pub fn run_on<F, R>(&mut self, f: F) -> Result<R::Item, R::Error>
|
||||||
|
where
|
||||||
|
F: FnOnce() -> R,
|
||||||
|
R: IntoFuture,
|
||||||
|
{
|
||||||
|
self.rt.block_on(lazy(|| f().into_future()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Spawn future to the current runtime
|
/// Spawn future to the current runtime
|
||||||
pub fn spawn<F>(&mut self, fut: F)
|
pub fn spawn<F>(&mut self, fut: F)
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user