Always yield thread when a promise is returned.

This commit is contained in:
Tim Mickel 2016-06-28 13:39:44 -04:00
parent 9881ee76b9
commit 9a7ab57f6f

View file

@ -93,6 +93,11 @@ var execute = function (sequencer, thread) {
typeof primitiveReportedValue.then === 'function' typeof primitiveReportedValue.then === 'function'
); );
if (isPromise) { if (isPromise) {
if (thread.status === Thread.STATUS_RUNNING) {
// Primitive returned a promise; automatically yield thread.
thread.status = Thread.STATUS_YIELD;
}
// Promise handlers
primitiveReportedValue.then(function(resolvedValue) { primitiveReportedValue.then(function(resolvedValue) {
// Promise resolved: the primitive reported a value. // Promise resolved: the primitive reported a value.
if (DEBUG_BLOCK_CALLS) { if (DEBUG_BLOCK_CALLS) {
@ -107,8 +112,7 @@ var execute = function (sequencer, thread) {
console.warn('primitive rejected promise: ', rejectionReason); console.warn('primitive rejected promise: ', rejectionReason);
} }
sequencer.proceedThread(thread); sequencer.proceedThread(thread);
} });
);
} else if (thread.status === Thread.STATUS_RUNNING) { } else if (thread.status === Thread.STATUS_RUNNING) {
if (DEBUG_BLOCK_CALLS) { if (DEBUG_BLOCK_CALLS) {
console.log('reporting value: ', primitiveReportedValue); console.log('reporting value: ', primitiveReportedValue);