"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; };