ysmood / yaku

A lightweight promise library
https://tonicdev.com/ysmood/yaku
MIT License
291 stars 28 forks source link

Bind to Angular 1.x digest? #50

Closed lifenautjoe closed 7 years ago

lifenautjoe commented 7 years ago

Bluebird provides the Promise.setScheduler method to bind with the angular digest cycle.

// This will synchronize bluebird promise queue flushing with angulars queue flushing
// Angular is also now responsible for choosing the actual scheduler
Promise.setScheduler(function(fn) {
    $rootScope.$evalAsync(fn);
});

Can the same thing be achieved with Yaku?

ysmood commented 7 years ago

Do you mean https://github.com/ysmood/yaku#yakunexttick?

ysmood commented 7 years ago

Yaku is more flexible than Bluebird, except the async scheduler, you can also set your own Symbol, Species, etc. Bluebird cannot do that.

lifenautjoe commented 7 years ago

Sadly with no scheduler, I found no way to make it work.

ysmood commented 7 years ago

Are you sure you understand what I said? I said please check the nextTick API of Yaku, it's the same with Bluebird's setScheduler.

const Promise = require('yaku')
Promise.nextTick = function(fn) {
    $rootScope.$evalAsync(fn);
}
lifenautjoe commented 7 years ago

Oh, no I didn't, thought you meant there was none with the "Yaku is more flexible than Bluebird, except the async scheduler". Will try it out. Thanks.

lifenautjoe commented 7 years ago

Never came back to this. It works, thanks!