Licence
—
Version
0.2.3
Deps
0
Size
4 kB
Vulns
0
Weekly
0
fn-buffer
Make your function buffer calls till you flush.
Useful to make Backtrace logging.
Install
npm install fn-buffer
API
new BufferedFunction(fn, opts)
fn<function>(required)The function to buffer calls ofopts[number|object]Options orcapacityopts.capacity[number=10]Capacity of the ring-buffer of the callsopts.flush[number=capacity]Auto-flush when buffer gets fullopts.reverse[boolean]Reverse the order of buffer calls
Example
import BufferedFunction from 'fn-buffer'
const bufferedLog = new BufferedFunction(console.log);
bufferedLog('a')
bufferedLog('b')
bufferedLog('c')
bufferedLog('d')
bufferedLog('e')
/* Doesn't log anything yet */
bufferedLog.flush();
/* Logs everything at once */
Backtrace logging
This can be used to create backtrace-logging:
import BufferedFunction from 'fn-buffer'
export const debug = new BufferedFunction(console.debug, { flush: 0 })
process.on('uncaughtExceptionMonitor', debug.flush)
This debug function will only log to console in the event of an uncaughtException.
See backtrace-logging for a module that does exactly this.