Git Product home page Git Product logo

Comments (12)

domenic avatar domenic commented on May 22, 2024

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.

avih avatar avih commented on May 22, 2024

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.

domenic avatar domenic commented on May 22, 2024

The spec doesn't real with resolve or reject though. But it does deal with every onFulfilled passed to then.

from promises-tests.

avih avatar avih commented on May 22, 2024

True that...

from promises-tests.

sterpe avatar sterpe commented on May 22, 2024

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.

stefanpenner avatar stefanpenner commented on May 22, 2024

@sterpe I believe this being left unspecified is intentional

from promises-tests.

domenic avatar domenic commented on May 22, 2024

@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 avatar stefanpenner commented on May 22, 2024

@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.

domenic avatar domenic commented on May 22, 2024

Well, I guess it depends on perspective. But this is not an unspecified loophole. This is a very well-specified issue.

from promises-tests.

stefanpenner avatar stefanpenner commented on May 22, 2024

@domenic ah ok. I then believe my wording was incorrect. unspecified -> untested

from promises-tests.

sterpe avatar sterpe commented on May 22, 2024

@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.

sterpe avatar sterpe commented on May 22, 2024

Or rather potential performance impact since you are ceding the thread back between the on fulfillment handler resolution.

from promises-tests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.