1.0.0 • Published 4 years ago

high-pass-caller v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

high-pass-caller

Build Status

Wrap a function that is called only if the wrapper is called fast enough.

Motivation

This package was created to monitor the synchronization status between two processes. Those processes could be out of sync for very short periods while the synchronization logic is catching up. But several checks finding sync issues should trigger an alarm.

Installation

npm install high-pass-caller

Usage

const highPassCaller = require('high-pass-caller')

const wrapped = highPassCaller(2, 100, console.log)

setTimeout(() => wrapped('not logged'), 0)
setTimeout(() => wrapped('not logged either'), 200)
setTimeout(() => wrapped('two calls within 100ms!'), 250)
setTimeout(() => wrapped('not logged, warming down'), 400)

API

highPassCaller(times, time, fn) ⇒ function

Wrap a function that is called only if the wrapper is called fast enough.

Returns: function - The wrapped function.

ParamTypeDescription
timesnumberThe number of calls.
timenumberThe time window to count the calls in ms.
fnfunctionThe function to be called.

License

MIT