ekibun / flutter_qjs

A quickjs engine for flutter.
https://pub.dev/packages/flutter_qjs
MIT License
146 stars 28 forks source link

IsolateFunction async #19

Closed MoonRune closed 3 years ago

MoonRune commented 3 years ago
  await setToGlobalObject.invoke(["http", (String url) {
    return Dio().get(url).then((response) => response.data);
  }]);

in my demo, it return future instead of future. event i change the code to: await setToGlobalObject.invoke(["http", (String url) async { return (await Dio().get(url)).toString(); }]); is there any way to get reusult?

ekibun commented 3 years ago

Plugin wraps the parameters and returns automatically. Both your demo returns Future in the function, and you would get Promise in Javascript side. you can get result with await IN JAVASCRIPT:

(async (url) => {
   var rsp = await http(url);
   /** or **/
  http(url).then((rsp) => {
     /** your code here **/
  })
})()

If you want to get the return value directly. you SHOULD NOT use async syntax or return Future in the function:

await setToGlobalObject.invoke(["http", (String url) {
  return "directly";
}]);
MoonRune commented 3 years ago

thanks. i want my js code run after dart future task done. it should be related with dart microtask .