summaryrefslogtreecommitdiff
path: root/cli/tokio_util.rs
blob: 017013b3b6a19ec3b7379a8c6df3dee690f1268f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2018-2020 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);
}