Skip to content

promisified function does not trigger setScheduler #1023

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

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

promisified function does not trigger setScheduler #1023

sterling opened this issue Feb 26, 2016 · 11 comments

Comments

@sterling
Copy link

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
Copy link
Author

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
Copy link
Owner

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

@sterling
Copy link
Author

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

@benjamingr
Copy link
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.

@sterling
Copy link
Author

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

@sterling
Copy link
Author

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
Copy link

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
Copy link
Owner

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
Copy link
Author

sterling commented Apr 7, 2016

Yes, I am using a custom scheduler

@tkambler
Copy link

tkambler commented Apr 8, 2016

Correct.

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

4 participants