Skip to content

Call JS-function that returns promise #1087

Answered by lahma
kresmonkking asked this question in Q&A
Discussion options

You must be logged in to vote

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);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kresmonkking
Comment options

Answer selected by kresmonkking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1084 on February 15, 2022 05:48.