fix misplaced import.relax lifetime bound for actix-rt

This commit is contained in:
fakeshadow 2020-10-20 09:39:53 +08:00
parent 9b5400aa27
commit 05d8551066
5 changed files with 34 additions and 7 deletions

View File

@ -8,7 +8,8 @@
### Changed
* update tokio to 0.3
* Remove `'static` lifetime requirement for `Runtime::block_on`. The method would accept a &Self when calling.
* Remove `'static` lifetime requirement for `Runtime::block_on` and `SystemRunner::block_on`. These methods would accept a &Self when calling.
* Remove `'static` lifetime requirement for `System::run`
## [1.1.1] - 2020-04-30

View File

@ -65,7 +65,7 @@ impl Builder {
/// Function `f` get called within tokio runtime context.
pub fn run<F>(self, f: F) -> io::Result<()>
where
F: FnOnce() + 'static,
F: FnOnce(),
{
self.create_runtime(f).run()
}
@ -87,7 +87,7 @@ impl Builder {
fn create_runtime<F>(self, f: F) -> SystemRunner
where
F: FnOnce() + 'static,
F: FnOnce(),
{
let (stop_tx, stop) = channel();
let (sys_sender, sys_receiver) = unbounded();
@ -179,9 +179,9 @@ impl SystemRunner {
}
/// Execute a future and wait for result.
pub fn block_on<F, O>(&mut self, fut: F) -> O
pub fn block_on<F, O>(&self, fut: F) -> O
where
F: Future<Output = O> + 'static,
F: Future<Output = O>,
{
Arbiter::run_system(Some(&self.rt));
let res = self.rt.block_on(fut);

View File

@ -256,7 +256,7 @@ impl System {
/// Function `f` get called within tokio runtime context.
pub fn run<F>(f: F) -> io::Result<()>
where
F: FnOnce() + 'static,
F: FnOnce(),
{
Self::builder().run(f)
}

View File

@ -112,3 +112,28 @@ fn join_current_arbiter() {
"local_join should await only for the already spawned futures"
);
}
#[test]
fn non_static_block_on() {
let string = String::from("test_str");
let str = string.as_str();
let sys = actix_rt::System::new("borrow some");
sys.block_on(async {
actix_rt::time::sleep(Duration::from_millis(1)).await;
assert_eq!("test_str", str);
});
let rt = actix_rt::Runtime::new().unwrap();
rt.block_on(async {
actix_rt::time::sleep(Duration::from_millis(1)).await;
assert_eq!("test_str", str);
});
actix_rt::System::run(|| {
assert_eq!("test_str", str);
actix_rt::System::current().stop();
} ).unwrap();
}

View File

@ -42,7 +42,6 @@ impl Signals {
#[cfg(unix)]
{
use actix_rt::signal::unix;
use futures_util::stream::Stream;
let mut streams = Vec::new();
@ -86,6 +85,8 @@ impl Future for Signals {
}
#[cfg(unix)]
{
use futures_util::stream::Stream;
for idx in 0..self.streams.len() {
loop {
match Pin::new(&mut self.streams[idx].1).poll_next(cx) {