Initial commit

master
Sven Slootweg 6 years ago
commit 5345666120

2
.gitignore vendored

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

@ -0,0 +1,27 @@
"use strict";
const Promise = require("bluebird");
const ms = require("ms");
const promiseDelaySince = require("@joepie91/promise-delay-every");
module.exports = function rateLimitedStream(interval) {
let intervalInMilliseconds = (typeof interval === "number")
? interval
: ms(interval);
let delayer = promiseDelaySince(intervalInMilliseconds);
return {
description: `rate-limited stream (1 per ${interval})`,
read: (source) => {
return Promise.try(() => {
return delayer();
}).then(() => {
return source.read();
});
},
abort: (source, reason) => {
source.abort(reason);
}
}
};

@ -0,0 +1,13 @@
{
"name": "@ppstreams/rate-limit",
"version": "1.0.0",
"main": "index.js",
"repository": "git@git.cryto.net:joepie91/ppstreams-rate-limit.git",
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"dependencies": {
"@joepie91/promise-delay-every": "^1.0.0",
"bluebird": "^3.5.4",
"ms": "^2.1.1"
}
}
Loading…
Cancel
Save