jerryscript
jerryscript copied to clipboard
using jerry_promise() and jerry_run_jobs() call(s)
I wondering how to deal with programatically created promises (jerry_promise()) and jerry_run_jobs() call or (calls !)
I try to implement a setTimeout native function that returns a promise.
script:
new Promise(function(resolve) {
resolve('Hello, World!');
})
.then(function(x) {
print(x);
return setTimeout(1000);
})
.then(function(x) {
print('timeout Ok');
})
pseudo main.c (partially from API-REFERENCE)
run the script
while (true)
ret = jerry_run_jobs()
if ret is not an exception
break;
output:
Hello, World!
... I also expect to see "timeout Ok"
- should I assume that the running script still have pending promises even if
jerry_run_jobs()returnsundefined?- if so, how to detect that my running script has no more pending promise (and then I can gracefully exit) ?
- should I use
jerry_promise_on_eventto count my promises, and exit if it reach 0 ?