W3cubDocs

/Bluebird

Promise.setScheduler

Promise.setScheduler(function(function fn) scheduler) -> function

Scheduler should be a function that asynchronously schedules the calling of the passed in function:

// This is just an example of how to use the api, there is no reason to do this
Promise.setScheduler(function(fn) {
    setTimeout(fn, 0);
});

Setting a custom scheduler could be necessary when you need a faster way to schedule functions than bluebird does by default. It also makes bluebird possible to use in platforms where normal timing constructs like setTimeout and process.nextTick are not available (like Nashhorn).

You can also use it as a hook:

// 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);
});

Danger - in order to keep bluebird promises Promises/A+ compliant a scheduler that executes the function asynchronously (like the examples in this page) must be used.

© 2013–2018 Petka Antonov
Licensed under the MIT License.
http://bluebirdjs.com/docs/api/promise.setscheduler.html