Download node_modules/bottleneck/lib/Batcher.js from mikmc5/aistats: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/mikmc5/aistats/resolve/main/node_modules/bottleneck/lib/Batcher.js
- Command line
-
hf download hf://spaces/mikmc5/aistats/node_modules/bottleneck/lib/Batcher.js
-
curl -L -o Batcher.js https://huggingface.co/spaces/mikmc5/aistats/resolve/main/node_modules/bottleneck/lib/Batcher.js
1.28 kB
| ; | |
| var Batcher, Events, parser; | |
| parser = require("./parser"); | |
| Events = require("./Events"); | |
| Batcher = function () { | |
| class Batcher { | |
| constructor(options = {}) { | |
| this.options = options; | |
| parser.load(this.options, this.defaults, this); | |
| this.Events = new Events(this); | |
| this._arr = []; | |
| this._resetPromise(); | |
| this._lastFlush = Date.now(); | |
| } | |
| _resetPromise() { | |
| return this._promise = new this.Promise((res, rej) => { | |
| return this._resolve = res; | |
| }); | |
| } | |
| _flush() { | |
| clearTimeout(this._timeout); | |
| this._lastFlush = Date.now(); | |
| this._resolve(); | |
| this.Events.trigger("batch", this._arr); | |
| this._arr = []; | |
| return this._resetPromise(); | |
| } | |
| add(data) { | |
| var ret; | |
| this._arr.push(data); | |
| ret = this._promise; | |
| if (this._arr.length === this.maxSize) { | |
| this._flush(); | |
| } else if (this.maxTime != null && this._arr.length === 1) { | |
| this._timeout = setTimeout(() => { | |
| return this._flush(); | |
| }, this.maxTime); | |
| } | |
| return ret; | |
| } | |
| } | |
| ; | |
| Batcher.prototype.defaults = { | |
| maxTime: null, | |
| maxSize: null, | |
| Promise: Promise | |
| }; | |
| return Batcher; | |
| }.call(void 0); | |
| module.exports = Batcher; |