Call JS-function that returns promise #1087
Answered
by
lahma
kresmonkking
asked this question in
Q&A
-
When I register JS-function that returns promise and then call it an exception occurs: Code that reproduces the error: const string jsCode = @"
let promise = new Promise((resolve, reject) => {
resolve(true);
});
test(() => promise);";
var engine = new Engine();
engine.SetValue("test", new Action<Func<object>>(fn => { fn(); })); // also tried Func<ExpandoObject>, Func<Task<bool>>, Func<JsValue> without success
engine.Execute(jsCode); Tried to fix it but cannot understand how to correctly do it. |
Beta Was this translation helpful? Give feedback.
Answered by
lahma
Feb 15, 2022
Replies: 1 comment 1 reply
-
You should try to have JsValue as your action parameter, this works for me at least. const string jsCode = @"
let promise = new Promise((resolve, reject) => {
resolve(true);
});
test(() => promise);";
var engine = new Engine();
JsValue promise = null;
engine.SetValue("test", new Action<JsValue>(fn =>
{
promise = fn.Call();
}));
engine.Execute(jsCode);
// ObjectInstance which is actually internal PromiseInstance
Assert.NotNull(promise); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
kresmonkking
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should try to have JsValue as your action parameter, this works for me at least.