Make example wait so it can process before getting the shutdown signal

This commit is contained in:
asonix 2018-11-06 21:52:57 -06:00
parent a142eb2d3f
commit ba758b19ab

View file

@ -1,6 +1,8 @@
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
use std::time::Duration;
use failure::Error; use failure::Error;
use futures::{ use futures::{
future::{lazy, IntoFuture}, future::{lazy, IntoFuture},
@ -42,8 +44,9 @@ fn main() {
dotenv::dotenv().ok(); dotenv::dotenv().ok();
env_logger::init(); env_logger::init();
tokio::run(lazy(|| { tokio::run(
let mut runner = JobRunner::new(1234, 8, "example-db"); lazy(|| {
let mut runner = JobRunner::new(1234, 4, "example-db");
runner.register_processor(MyProcessor); runner.register_processor(MyProcessor);
let handle = runner.spawn(); let handle = runner.spawn();
@ -65,6 +68,26 @@ fn main() {
some_usize: 8, some_usize: 8,
other_usize: 13, other_usize: 13,
}, },
MyJobArguments {
some_usize: 21,
other_usize: 34,
},
MyJobArguments {
some_usize: 55,
other_usize: 89,
},
MyJobArguments {
some_usize: 144,
other_usize: 233,
},
MyJobArguments {
some_usize: 377,
other_usize: 610,
},
MyJobArguments {
some_usize: 987,
other_usize: 1597,
},
]; ];
let _: Vec<_> = jobs let _: Vec<_> = jobs
@ -78,6 +101,15 @@ fn main() {
}) })
.collect(); .collect();
Ok(()) Ok(handle)
})); })
.and_then(|handle| {
tokio::timer::Delay::new(tokio::clock::now() + Duration::from_secs(2))
.map(move |_| {
let _ = handle;
()
})
.map_err(|_| ())
}),
);
} }