flutter_js icon indicating copy to clipboard operation
flutter_js copied to clipboard

Need to call executePendingJob() by timer to process background promises for QuickJS

Open romannep opened this issue 2 years ago • 1 comments

    const exampleJs = '''
    const testAsync = async () => {
      await new Promise(resolve => setTimeout(resolve, 2000));
      console.log('You will never see this message unless calling jsRuntime.executePendingJob() by timer');
    };
    testAsync();
    '''
    jsRuntime.evaluate(exampleJs);

Without extra movements we will never see message to console.

Can be fixed by

    if (Platform.isWindows || Platform.isAndroid || Platform.isLinux ) {
      Timer.periodic(Duration(milliseconds: 50), (timer) {
        jsRuntime.executePendingJob();
      });
    }

(any interval can be set based on needs)

May be this is intentional behaviour, but it worth to be mentioned in doc.

romannep avatar Jan 15 '23 11:01 romannep

call jsRuntime.handlerPromise?

liruohrh avatar Jul 11 '24 23:07 liruohrh