Skip to content

Commit

Permalink
feat: re-export tokio runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Duyet Le committed Oct 12, 2022
1 parent 1463e41 commit d5654a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ authors = ["Duyet Le <me@duyet.net>"]
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"] }
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions tests/runtime.rs
Original file line number Diff line number Diff line change
@@ -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");
}

0 comments on commit d5654a0

Please sign in to comment.