Browse Source

Initial commit

master
Sven Slootweg 2 years ago
commit
858f393a7a
  1. 2
      .gitignore
  2. 32
      index.js
  3. 12
      package.json

2
.gitignore

@ -0,0 +1,2 @@
node_modules
yarn.lock

32
index.js

@ -0,0 +1,32 @@
"use strict";
const Promise = require("bluebird");
const propagateAbort = require("@ppstreams/propagate-abort");
const { isEndOfStream } = require("@ppstreams/end-of-stream-marker");
module.exports = function greedySinkStream(description, callback) {
return {
description: `greedy sink stream (${description})`,
abort: propagateAbort,
read: function produceValue_greedySinkStream(source) {
let lastResult;
function attemptRead() {
return Promise.try(() => {
return source.read();
}).then((value) => {
return callback(value);
}).then((result) => {
lastResult = result;
return attemptRead();
}).catch(isEndOfStream, () => {
/* Don't attempt to do another read, we're done. We return whatever value we got last from the specified callback. */
return lastResult;
});
}
return attemptRead();
}
};
};

12
package.json

@ -0,0 +1,12 @@
{
"name": "@ppstreams/greedy-sink",
"version": "0.1.0",
"main": "index.js",
"repository": "http://git.cryto.net/ppstreams/greedy-sink.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"dependencies": {
"@ppstreams/propagate-abort": "^0.1.2",
"bluebird": "^3.5.4"
}
}
Loading…
Cancel
Save