jerryscript-project / jerryscript

Ultra-lightweight JavaScript engine for the Internet of Things.
https://jerryscript.net
Apache License 2.0
6.89k stars 669 forks source link

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

Open FranckFreiburger opened 1 year ago

FranckFreiburger commented 1 year ago

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"