|
|
|
@ -1,19 +1,19 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
const consumable = require("@joepie91/consumable");
|
|
|
|
|
|
|
|
|
|
module.exports = function createPromiseListener() {
|
|
|
|
|
let listeners = [];
|
|
|
|
|
let listeners = consumable([]);
|
|
|
|
|
|
|
|
|
|
function consumeListeners() {
|
|
|
|
|
/* To ensure that a resolve/reject is atomic, and can never apply to the same listener queue twice. */
|
|
|
|
|
let consumedListeners = listeners;
|
|
|
|
|
listeners = [];
|
|
|
|
|
return consumedListeners;
|
|
|
|
|
return listeners.replace([]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
listen: function () {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
listeners.push({ resolve, reject });
|
|
|
|
|
listeners.peek().push({ resolve, reject });
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
resolve: function (value) {
|
|
|
|
@ -27,4 +27,4 @@ module.exports = function createPromiseListener() {
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|