Skip to content

Commit

Permalink
Merge pull request #443 from ringo/native-promise
Browse files Browse the repository at this point in the history
Adapt to Rhino's NativePromise
  • Loading branch information
botic authored Jan 12, 2022
2 parents 4459f59 + da2b2a9 commit 57c2bb9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/org/ringojs/engine/RingoGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ public static Object spawn(Context cx, Scriptable thisObj,
public Object call() {
return cxfactory.call(new ContextAction<Object>() {
public Object run(Context cx) {
return function.call(cx, scope, scope, fnArgs);
Object result = function.call(cx, scope, scope, fnArgs);
cx.processMicrotasks();
return result;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/org/ringojs/engine/RingoWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public Object invoke(Object module, Object function, Object... args)
}
} finally {
releaseWorker(previous);
cx.processMicrotasks();
Context.exit();
}
}
Expand Down
1 change: 1 addition & 0 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.testBinary = require('./binary/all');
exports.testRepository = require('./repository/all');
exports.testIo = require('./io_test');
exports.testModules = require('./modules/all');
exports.testRhino = require("./rhino/all");

// Also include integration tests
exports.testIntegration = require('./integration-tests/all');
Expand Down
4 changes: 4 additions & 0 deletions test/rhino/all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports.testArrowFunctions = require("./arrow_functions");
exports.testConstStatement = require("./const_statement");
exports.testLetStatement = require("./let_statement");
exports.testPromise = require("./promise_test");
22 changes: 22 additions & 0 deletions test/rhino/promise_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const assert = require("assert");
const {Semaphore} = require("ringo/concurrent");

exports.testResolve = () => {
const semaphore = new Semaphore();
let expected = false;
spawn(() => {
return new Promise(resolve => {
java.lang.Thread.sleep(100);
resolve(true);
}).then(value => {
expected = value;
semaphore.signal();
});
});
semaphore.tryWait(150);
assert.isTrue(expected);
};

if (require.main === module) {
require("system").exit(require("test").run(module.id));
}

0 comments on commit 57c2bb9

Please sign in to comment.