Browse Source

Move p-listen to stand-alone package

master
Sven Slootweg 3 months ago
parent
commit
6dbc0597fe
  1. 7
      index.js
  2. 3
      package.json
  3. 28
      promise-listener.js
  4. 7
      yarn.lock

7
index.js

@ -3,16 +3,15 @@
const Promise = require("bluebird");
const pDefer = require("p-defer");
const defaultValue = require("default-value");
const promiseListener = require("./promise-listener");
const pListen = require("p-listen");
module.exports = function createRequestQueue(options = {}) {
// FIXME: Validatem, docs
let requestBuffer = [];
let responseBuffer = [];
let seenError;
let requestDrainListener = promiseListener();
let responseDrainListener = promiseListener();
let requestDrainListener = pListen();
let responseDrainListener = pListen();
function failAllRequests(error) {
let failedRequests = requestBuffer;

3
package.json

@ -9,7 +9,8 @@
"@joepie91/consumable": "^1.0.1",
"bluebird": "^3.7.2",
"default-value": "^1.0.0",
"p-defer": "^3"
"p-defer": "^3",
"p-listen": "^0.1.0"
},
"devDependencies": {
"@joepie91/eslint-config": "^1.1.0",

28
promise-listener.js

@ -1,28 +0,0 @@
"use strict";
const consumable = require("@joepie91/consumable");
// TODO: Move to separate package, p-listener or something
module.exports = function createPromiseListener() {
let listeners = consumable([]);
function consumeListeners() {
/* To ensure that a resolve/reject is atomic, and can never apply to the same listener queue twice. */
return listeners.replace([]);
}
return {
listen: function () {
return new Promise((resolve, _reject) => {
listeners.peek().push(resolve);
});
},
notify: function (promise) {
consumeListeners().forEach((listener) => {
// Docs: Pass in a rejected promise to produce a rejection on listeners
listener(promise);
});
}
};
};

7
yarn.lock

@ -606,6 +606,13 @@ p-defer@^3:
resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-3.0.0.tgz#d1dceb4ee9b2b604b1d94ffec83760175d4e6f83"
integrity sha512-ugZxsxmtTln604yeYd29EGrNhazN2lywetzpKhfmQjW/VJmhpDmWbiX+h0zL8V91R0UXkhb3KtPmyq9PZw3aYw==
p-listen@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/p-listen/-/p-listen-0.1.0.tgz#3964f8e6f91e275746dc36cd0912f6b415cc1fb9"
integrity sha512-3LpzYasV+6GZEEamAYqZxbdKpI4QA0PtBZK/Eehfv4ZYUhr4k2POuxUpDrdn2RYIsCVRsSKStfRsiljIE0LbEg==
dependencies:
"@joepie91/consumable" "^1.0.1"
parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"

Loading…
Cancel
Save