2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-11-17 01:17:47 +01:00
|
|
|
use std::future::Future;
|
2018-09-18 11:53:16 -07:00
|
|
|
use tokio;
|
2019-04-23 16:27:44 -04:00
|
|
|
use tokio::runtime;
|
|
|
|
|
2019-03-14 19:17:52 -04:00
|
|
|
pub fn run<F>(future: F)
|
|
|
|
where
|
2020-01-01 20:21:27 +05:30
|
|
|
F: Future<Output = ()> + Send + 'static,
|
2019-03-14 19:17:52 -04:00
|
|
|
{
|
2019-12-30 14:57:17 +01:00
|
|
|
let mut rt = runtime::Builder::new()
|
|
|
|
.threaded_scheduler()
|
|
|
|
.enable_all()
|
|
|
|
.thread_name("deno")
|
|
|
|
.build()
|
|
|
|
.expect("Unable to create Tokio runtime");
|
2020-01-01 20:21:27 +05:30
|
|
|
rt.block_on(future);
|
2019-04-14 16:07:24 -04:00
|
|
|
}
|
|
|
|
|
2019-07-31 17:02:20 +02:00
|
|
|
pub fn run_on_current_thread<F>(future: F)
|
|
|
|
where
|
2020-01-01 20:21:27 +05:30
|
|
|
F: Future<Output = ()> + Send + 'static,
|
2019-07-31 17:02:20 +02:00
|
|
|
{
|
2019-12-30 14:57:17 +01:00
|
|
|
let mut rt = runtime::Builder::new()
|
|
|
|
.basic_scheduler()
|
|
|
|
.enable_all()
|
|
|
|
.thread_name("deno")
|
|
|
|
.build()
|
|
|
|
.expect("Unable to create Tokio runtime");
|
2020-01-01 20:21:27 +05:30
|
|
|
rt.block_on(future);
|
2019-07-31 17:02:20 +02:00
|
|
|
}
|