flutter_js
flutter_js copied to clipboard
Need to call executePendingJob() by timer to process background promises for QuickJS
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.
call jsRuntime.handlerPromise?