jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

using jerry_promise() and jerry_run_jobs() call(s)

Open FranckFreiburger opened this issue 3 years ago • 0 comments

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() returns undefined ?
    • 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_event to count my promises, and exit if it reach 0 ?

FranckFreiburger avatar Jan 13 '23 13:01 FranckFreiburger