-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support async lambda and udf (#2239)
* feat: Support `async` lambda and udf * Clean up deno worker abstraction a bit --------- Co-authored-by: Jesse Bakker <[email protected]>
- Loading branch information
1 parent
605709c
commit 30d5510
Showing
11 changed files
with
176 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function () { | ||
throw new Error("exception from javascript"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async function () { | ||
const response = await fetch('https://api.github.com/repos/getdozer/dozer/commits?per_page=1'); | ||
const json = await response.json(); | ||
return json; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async function () { | ||
const response = await fetch("https://github.com/getdozer/dozer/commits"); | ||
const json = await response.json(); | ||
return json; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function (input) { | ||
return input * input; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use dozer_types::json_types::json; | ||
|
||
use super::*; | ||
|
||
async fn call_function(module: &str, args: Vec<JsonValue>) -> Result<JsonValue, AnyError> { | ||
let (mut runtime, functions) = Runtime::new(vec![format!("src/runtime/{module}")]).await?; | ||
runtime.call_function(functions[0], args).await | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_runtime() { | ||
assert_eq!( | ||
call_function("square.js", vec![json!(2.0)]).await.unwrap(), | ||
json!(4.0) | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_function_call_exception() { | ||
let error = call_function("exception.js", vec![]).await.unwrap_err(); | ||
assert_eq!(error.to_string(), "uncaught javascript exception"); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_async_function_call() { | ||
let Ok(result) = call_function("fetch.js", vec![]) | ||
.await | ||
.unwrap() | ||
.into_array() | ||
else { | ||
panic!("expected array") | ||
}; | ||
assert!(!result.is_empty()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_async_function_call_exception() { | ||
let error = call_function("fetch_exception.js", vec![]) | ||
.await | ||
.unwrap_err(); | ||
assert!(error.to_string().starts_with("SyntaxError: ")); | ||
} |
Oops, something went wrong.