Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fn delay_future() -> Box<Future<Item = (), Error = io::Error> + Send> {
let wait_time = Duration::from_millis(100);
let now = Instant::now();
let task = Interval::new(now, wait_time)
.map_err(|e| panic!("interval errored; err={:?}", e))
.take(10)
.for_each(|instant| {
println!("fire; instant={:?}", instant);
Ok(())
});
Box::new(task)
}
#[get("/")]
pub fn tryme(pool_f: State<Runtime>) -> &'static str {
let ex = pool_f.executor();
ex.spawn(delay_future().map_err(|e| eprintln!("Server error {}", e)));
"Hey there\n"
}
pub fn runner(_env: Environment) -> Result<rocket::Rocket, String> {
let pool_f = Builder::new()
.core_threads(4)
.build()
.unwrap();
let rocket = rocket::ignite()
.mount(
"/",
routes![
// routes::udemy::get_results,
tryme,
],
)
.manage(pool_f)
.register(catchers![
routes::errors::not_found,
]);
Ok(rocket)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.