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

promisified function does not trigger setScheduler #1023

Closed
sterling opened this Issue Feb 26, 2016 · 11 comments

Comments

Projects
None yet
4 participants
@sterling

sterling commented Feb 26, 2016

bluebird 3.3.3, Chrome 48, angular 1.5.0

Example in this fiddle: https://jsfiddle.net/Lmac0kLw/5/

When using promisify on an async function, it appears that setScheduler is not called when the promise resolves. In my jsfiddle, I use angular to update the text to HelloWorld, but it does not change.

There are a few ways to remedy this:

  1. Add a $scope.$apply(); which obviously defeats the purpose of setScheduler.
  2. Use a normal promise in place of pAsync:
Promise.resolve()
  .then(function() {
    $scope.hello = 'HelloWorld';
  });

As I understand it, there should be no difference between the promisified call vs the normal promise. Is this an actual bug? Or am I not understanding something?

@sterling

This comment has been minimized.

Show comment
Hide comment
@sterling

sterling Feb 27, 2016

I just tested the same jsfiddle with bluebird v2.10.2 and it worked as expected. Upgrading it to 3.0.0 breaks it.

sterling commented Feb 27, 2016

I just tested the same jsfiddle with bluebird v2.10.2 and it worked as expected. Upgrading it to 3.0.0 breaks it.

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Feb 27, 2016

Owner

This is an optimization because the promisifier can tell when scheduler is not needed

Owner

petkaantonov commented Feb 27, 2016

This is an optimization because the promisifier can tell when scheduler is not needed

@sterling

This comment has been minimized.

Show comment
Hide comment
@sterling

sterling Feb 27, 2016

Can you explain a little further? Why is the scheduler not needed in this case?

sterling commented Feb 27, 2016

Can you explain a little further? Why is the scheduler not needed in this case?

@benjamingr

This comment has been minimized.

Show comment
Hide comment
@benjamingr

benjamingr Feb 27, 2016

Collaborator

Automatic promisification only applies to functions with the node (err, data) callback signature - you should not use it in client-side code.

As for what Petka is saying - bluebird will eagerly avoid defering actions when it can prove that the action has already been deferred by the platform. That is - in this case it can tell the action inside the promisified callback has executed asynchronously so it does not need to defer it further.

This should not be an issue with Angular since automatic promisification is irrelevant to it anyway.

Collaborator

benjamingr commented Feb 27, 2016

Automatic promisification only applies to functions with the node (err, data) callback signature - you should not use it in client-side code.

As for what Petka is saying - bluebird will eagerly avoid defering actions when it can prove that the action has already been deferred by the platform. That is - in this case it can tell the action inside the promisified callback has executed asynchronously so it does not need to defer it further.

This should not be an issue with Angular since automatic promisification is irrelevant to it anyway.

@sterling

This comment has been minimized.

Show comment
Hide comment
@sterling

sterling Feb 27, 2016

@benjamingr Thank you for the explanation. I guess my use case is a little unique in that I'm using Electron (http://electron.atom.io/) which means node style callbacks are common and may propogate up to angular (due to node modules being available from the "client-side").

sterling commented Feb 27, 2016

@benjamingr Thank you for the explanation. I guess my use case is a little unique in that I'm using Electron (http://electron.atom.io/) which means node style callbacks are common and may propogate up to angular (due to node modules being available from the "client-side").

@benjamingr

This comment has been minimized.

Show comment
Hide comment
@benjamingr

benjamingr Feb 27, 2016

Collaborator

Oh, interesting - you can probably work around it with monitoring turned on and scheduling a noop evalAsync when promises resolve - I wonder if the optimization should be opt out.

Collaborator

benjamingr commented Feb 27, 2016

Oh, interesting - you can probably work around it with monitoring turned on and scheduling a noop evalAsync when promises resolve - I wonder if the optimization should be opt out.

@sterling

This comment has been minimized.

Show comment
Hide comment
@sterling

sterling Feb 27, 2016

I will have to try out the monitoring. Opt out would be nice since for now I've just downgraded bluebird to 2.x

sterling commented Feb 27, 2016

I will have to try out the monitoring. Opt out would be nice since for now I've just downgraded bluebird to 2.x

@tkambler

This comment has been minimized.

Show comment
Hide comment
@tkambler

tkambler Apr 7, 2016

I just got bit by this, as well. Same use case - Electron. I have also had to downgrade to bluebird@2.10.2.

tkambler commented Apr 7, 2016

I just got bit by this, as well. Same use case - Electron. I have also had to downgrade to bluebird@2.10.2.

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Apr 7, 2016

Owner

I guess the optimization could be disabled when custom scheduler is in use. You are all using custom setScheduler right?

Owner

petkaantonov commented Apr 7, 2016

I guess the optimization could be disabled when custom scheduler is in use. You are all using custom setScheduler right?

@petkaantonov petkaantonov reopened this Apr 7, 2016

@sterling

This comment has been minimized.

Show comment
Hide comment
@sterling

sterling Apr 7, 2016

Yes, I am using a custom scheduler

sterling commented Apr 7, 2016

Yes, I am using a custom scheduler

@tkambler

This comment has been minimized.

Show comment
Hide comment
@tkambler

tkambler commented Apr 8, 2016

Correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment