Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q.when() is not resolved synchronously while Q() is #814

Open
jesantana opened this issue May 27, 2017 · 1 comment
Open

Q.when() is not resolved synchronously while Q() is #814

jesantana opened this issue May 27, 2017 · 1 comment

Comments

@jesantana
Copy link

I have a code similar to this in one of my tests.

var Q=require('q');

var staticWhen=Q.when(1);
var staticQ=Q(1);

function printStatusInfo(prom){
    console.log(prom.isPending());
    console.log(prom.isFulfilled());
    console.log(prom.inspect());
}

printStatusInfo(staticWhen);
printStatusInfo(staticQ);

and this outputs

staticWhen
true
false
{ state: 'pending' }

staticQ
false
true
{ state: 'fulfilled', value: 1 }

Only if you wait for the next tick you can have the static when promise fulfilled, while the static Q is fulfilled from the beginning.

I think this can be a problem if you substitute Q.when() for Q(), for example in a test that synchronously assert that the promise is fulfilled. Maybe it should be pointed in the docu that they behave differently in this case, because in the first paragraph of the reference says that they are equivalent.

@Jabokoe
Copy link

Jabokoe commented Jul 28, 2017

Hmm the docs first paragraph sais Q.when(X,Y) is equivalent to Q(X).then(Y). That is slighly different from saying Q.when(X) is equivalent to Q(X). It also states:

which will accept either a promise or a non-promise, and in the latter case create a fulfilled promise first

Maybe you can help me understand: If it is known that .then(Y) is fulfilled on the next tick then that means Q(X) has to be instantanious? So the behaviour can't change under those conditions? Because in my limited understanding making Q.(X) pending would make Q(X).then(Y) take two ticks... I'm not sure if that is accurate or if that is even breaking any expectations.

Have you checked whether Q(X).then() behaves equivalent to Q.when(X)?

I agree a clarification would be in order because neither the main readme nor the wiki docs are clear on the expected behaviour of when(X), only when(X,Y) is clearly defined right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants