You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
542 B
JavaScript

"use strict";
const Promise = require("bluebird");
const notifiedPromise = require("./notified-promise");
// FIXME: Move into separate package
module.exports = function createNotifiedWhen() {
let notifier = notifiedPromise();
function when(condition, callback) {
if (condition()) {
return callback();
} else {
return Promise.try(() => {
return notifier.wait();
}).then(() => {
return when(condition, callback);
});
}
}
when.notify = function notifyWhen() {
return notifier.notify();
};
return when;
};