Skip to content

Instantly share code, notes, and snippets.

@apiraino
Last active April 14, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apiraino/505a485bd6ac4536279d2f528245284d to your computer and use it in GitHub Desktop.
Save apiraino/505a485bd6ac4536279d2f528245284d to your computer and use it in GitHub Desktop.
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