mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 02:21:07 +01:00
add TestServerRuntime::run_on() method
This commit is contained in:
parent
b9d8a215b4
commit
21507d3da1
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-test-server"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix test server"
|
||||
keywords = ["network", "framework", "async", "futures"]
|
||||
|
@ -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<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
|
||||
pub fn spawn<F>(&mut self, fut: F)
|
||||
where
|
||||
|
Loading…
Reference in New Issue
Block a user