From 3293058945cdf7f6a1699bb3395d555052740dab Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 4 Jul 2021 01:12:55 +0200 Subject: [PATCH] Initial commit --- index.js | 20 ++++++++++++++++++++ package.json | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 index.js create mode 100644 package.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..c80c882 --- /dev/null +++ b/index.js @@ -0,0 +1,20 @@ +"use strict"; + +module.exports = function createResultBuffer() { + let buffer = []; + + return { + push: function (item) { + // NOTE: item should always be a Promise, either resolved or rejected! Use Promise.resolve or Promise.reject to wrap an item if necessary + // FIXME: Actually validate this + buffer.push(item); + }, + maybeRead: function (readCallback) { + if (buffer.length > 0) { + return buffer.shift(); + } else { + return readCallback(); + } + } + }; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..029ed0c --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "result-buffer", + "version": "0.1.0", + "main": "index.js", + "repository": "https://git.cryto.net/joepie91/result-buffer.git", + "author": "Sven Slootweg ", + "license": "WTFPL OR CC0-1.0" +}