Download node_modules/bottleneck/src/Batcher.coffee from mikmc5/aistats: direct link, hf CLI and curl.
- Browser
- Download file 792 Bytes
-
https://huggingface.co/spaces/mikmc5/aistats/resolve/main/node_modules/bottleneck/src/Batcher.coffee
- Command line
-
hf download hf://spaces/mikmc5/aistats/node_modules/bottleneck/src/Batcher.coffee
-
curl -L -o Batcher.coffee https://huggingface.co/spaces/mikmc5/aistats/resolve/main/node_modules/bottleneck/src/Batcher.coffee
792 Bytes
| parser = require "./parser" | |
| Events = require "./Events" | |
| class Batcher | |
| defaults: | |
| maxTime: null | |
| maxSize: null | |
| Promise: Promise | |
| constructor: (@options={}) -> | |
| parser.load @options, @defaults, @ | |
| @Events = new Events @ | |
| @_arr = [] | |
| @_resetPromise() | |
| @_lastFlush = Date.now() | |
| _resetPromise: -> | |
| @_promise = new @Promise (res, rej) => @_resolve = res | |
| _flush: -> | |
| clearTimeout @_timeout | |
| @_lastFlush = Date.now() | |
| @_resolve() | |
| @Events.trigger "batch", @_arr | |
| @_arr = [] | |
| @_resetPromise() | |
| add: (data) -> | |
| @_arr.push data | |
| ret = @_promise | |
| if @_arr.length == @maxSize | |
| @_flush() | |
| else if @maxTime? and @_arr.length == 1 | |
| @_timeout = setTimeout => | |
| @_flush() | |
| , @maxTime | |
| ret | |
| module.exports = Batcher | |