Comments (12)
The spec seems pretty clear that no matter what causes onFulfilled
to trigger, any onFulfilled
that is passed to then
must never be called with a dirty stack.
from promises-tests.
That's the interpretation issue I was referring to. I think it would have been clearer if the spec said "after the event loop turn which triggered the call, be it then
or resolve
or reject
"
from promises-tests.
The spec doesn't real with resolve or reject though. But it does deal with every onFulfilled passed to then.
from promises-tests.
True that...
from promises-tests.
Hi all,
This is also related to the interpretation of "after the event loop turn in which then is called, and with a fresh stack" as well so thought I'd pop it in here rather than new issue.
My promise implementation uses an internal trampoline queue (to cover the fresh stack/platform code aspect) & passes all current compliance tests but I'm concerned that I did not correctly implement the after event loop turn requirement...there doesn't seem to be any actual coverage of that requirement when dealing with adding a fulfilment handler to the same promise within a fulfillment handler to that promise.
I've modified a test from 2.2.4 to illustrate:
describe("Clean-stack execution ordering tests (fulfillment case)", function () {
....
specify("when one `onFulfilled` is added inside another `onFulfilled`", function (done) {
var promise = resolved();
var firstOnFulfilledFinished = false;
promise.then(function () {
var x
;
process.nextTick(function () {
x = 1;
});
promise.then(function () {
assert.strictEqual(firstOnFulfilledFinished, true);
assert.strictEqual(x, 1);
done();
});
firstOnFulfilledFinished = true;
});
});
Am I correct in assuming that A+ implementation would pass this test: I.e. then called in a fulfillment handler is fulfilled in the next event loop turn?
from promises-tests.
@sterpe I believe this being left unspecified is intentional
from promises-tests.
@stefanpenner nope.
@sterpe that test is a bit tricky because it's interleaving two "async queues": process.nextTick and the promise queue. The test of firstOnFulfilledFinished
is more useful than the test of x
, because it says literally whether the promise queue has unwound. The test of x
also tests that the nextTick queue has unwound. But that is not necessary for conformance because the stack will still be clean.
You can picture it this way:
promise queue: [], nextTick queue: []
promise queue: [<set x to undefined>], nextTick queue: [<set x to 1>]
promise queue: [<set x to undefined>, <assert x === 1>], nextTick queue: [<set x to 1>]
At this point a bunch of stuff has been enqueued, but no other code is ready to run, so our stack is empty. Now it's time to start dequeing stuff. Let's say that things have worked out so that the promise queue comes before the nextTick queue. Then we have:
run <set x to undefined>
promise queue: [<assert x === 1>], nextTick queue: [<set x to 1>]
stack is again empty.
run <assert x === 1> (it will fail)
promise queue: [], nextTick queue: [<set x to 1>]
stack is again empty
run <set x to 1>
promise queue: [], nextTick queue: []
done; no more queued event loop work items. Node can now exit; browser can now GC; etc.
So this shows how an implementation can be conforming but still fail the x === 1 test.
from promises-tests.
@stefanpenner nope.
I must be missing something because you followed this up with an explanation as to why this is left unspecified.
from promises-tests.
Well, I guess it depends on perspective. But this is not an unspecified loophole. This is a very well-specified issue.
from promises-tests.
@domenic ah ok. I then believe my wording was incorrect. unspecified
-> untested
from promises-tests.
@domenic, thanks for the clarification. I suppose then there's an unnecessary resolution speed penalty that an implementation would have to take in this situation waiting for the next tick queue to unwind in order to pass the 'x' test.
from promises-tests.
Or rather potential performance impact since you are ceding the thread back between the on fulfillment handler resolution.
from promises-tests.
Related Issues (20)
- Help wanted: Own tests or promises-tests tests? HOT 4
- Test suite passes even if clause 2.3.2 is not implemented HOT 1
- Add test case for very nested promises HOT 1
- mocha test runner failures HOT 7
- Add tests for Promise.all and Promise.race. HOT 1
- Can you assist me in satisfying promises aplus spec 2.2.4 in NodeJS? HOT 2
- How to run tests at requirebin?
- "just create a pull request" HOT 2
- Allow to specify the timeout HOT 3
- Promise.prototype.finally tests HOT 1
- resolve then reject miss test case
- 2.3.3 numberOfTimesThenWasRetrieved should not increment in then getter HOT 1
- Please create 1.x branch
- is it still useful? HOT 5
- NPM complains about security issues HOT 1
- RFE: Clarify intent re resolve(promise) HOT 1
- 2.3.3.js `x` is an object with normal Object.prototype
- Error `require`ing adapter file D:\my-promise\my-promise.js HOT 1
- what the purpose of these code is in file 2.1.2.js?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promises-tests.