From d5654a0026520f8ddaa49ee2be4693bfa349bd75 Mon Sep 17 00:00:00 2001 From: Duyet Le Date: Wed, 12 Oct 2022 16:30:35 +0700 Subject: [PATCH] feat: re-export tokio runtime --- Cargo.toml | 2 -- src/lib.rs | 1 + tests/runtime.rs | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/runtime.rs diff --git a/Cargo.toml b/Cargo.toml index 98c11af..20c0279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,4 @@ authors = ["Duyet Le "] anyhow = "1.0.65" deno_core = "0.154.0" deno_console = "0.72.0" - -[dev-dependencies] tokio = { version = "1.21.2", features = ["rt", "macros", "rt-multi-thread"] } diff --git a/src/lib.rs b/src/lib.rs index c15d108..971d83f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ use deno_core::{FsModuleLoader, JsRuntime, RuntimeOptions}; use std::{collections::HashMap, fmt::Display, rc::Rc}; pub use deno_core::{anyhow, op}; +pub use tokio::runtime::Runtime; /// Deno runtime pub struct DenoRunner { diff --git a/tests/runtime.rs b/tests/runtime.rs new file mode 100644 index 0000000..a260081 --- /dev/null +++ b/tests/runtime.rs @@ -0,0 +1,22 @@ +use deno_runner::{Builder, Runtime}; +use std::collections::HashMap; + +#[test] +fn test_tokio_runtime() { + // Using re-exported tokio runtime + let rt = Runtime::new().unwrap(); + let out = rt.block_on(async { + let custom_code = r#" + const add = (a, b) => a + b; + add(a, b) + "#; + + let runner = Builder::new().build(); + let vars = HashMap::from([("a", 1), ("b", 2)]); + let result = runner.run(custom_code, Some(vars)).await.unwrap(); + + result + }); + + assert_eq!(out, "3"); +}