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.
30 lines
534 B
JavaScript
30 lines
534 B
JavaScript
3 years ago
|
"use strict";
|
||
|
|
||
|
const pDefer = require("p-defer");
|
||
|
|
||
|
// FIXME: Move into separate package, and see if this can be used in other stream implementations too
|
||
|
|
||
|
module.exports = function createPromiseNotifier() {
|
||
|
let promise, resolve;
|
||
|
|
||
|
return {
|
||
|
wait: function () {
|
||
|
if (promise == null) {
|
||
|
let defer = pDefer();
|
||
|
promise = defer.promise;
|
||
|
resolve = defer.resolve;
|
||
|
}
|
||
|
|
||
|
return promise;
|
||
|
},
|
||
|
notify: function (value) {
|
||
|
if (resolve != null) {
|
||
|
resolve(value);
|
||
|
|
||
|
promise = null;
|
||
|
resolve = null;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
};
|