Last active
April 14, 2019 15:41
-
-
Save apiraino/505a485bd6ac4536279d2f528245284d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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