New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

fn-buffer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fn-buffer

Buffer function calls till you flush

0.2.0
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created

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 of
  • opts [number|object] Options or capacity
  • opts.capacity [number=10] Capacity of the ring-buffer of the calls
  • opts.flush [boolean|number=capacity] Auto-flush when buffer gets full
  • opts.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 = BufferedFunction(console.debug, { flush: false })
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.

FAQs

Package last updated on 01 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts