mirror of
https://github.com/denoland/deno.git
synced 2024-10-30 09:08:00 -04:00
55add2d366
tokio_util::run and tokio::run_on_current_thread should accept Future<Output=()> instead of Future<Output=Result<(), ()>>. Currently, all the passed futures have to add Ok(()) or futures::future::ok(()) unnecessarily to call this method.
30 lines
686 B
Rust
30 lines
686 B
Rust
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
use std::future::Future;
|
|
use tokio;
|
|
use tokio::runtime;
|
|
|
|
pub fn run<F>(future: F)
|
|
where
|
|
F: Future<Output = ()> + Send + 'static,
|
|
{
|
|
let mut rt = runtime::Builder::new()
|
|
.threaded_scheduler()
|
|
.enable_all()
|
|
.thread_name("deno")
|
|
.build()
|
|
.expect("Unable to create Tokio runtime");
|
|
rt.block_on(future);
|
|
}
|
|
|
|
pub fn run_on_current_thread<F>(future: F)
|
|
where
|
|
F: Future<Output = ()> + Send + 'static,
|
|
{
|
|
let mut rt = runtime::Builder::new()
|
|
.basic_scheduler()
|
|
.enable_all()
|
|
.thread_name("deno")
|
|
.build()
|
|
.expect("Unable to create Tokio runtime");
|
|
rt.block_on(future);
|
|
}
|