heartbeat
A good heartbeat timer
Installation
npm install jasonkuhrt-heartbeat
Example
var tcp = ;var heartbeat = ; tcp;
> npm start
...
... (some time passes, your app does stuff, then maybe...)
...
Socket timed out, destroying socket.
API
Heartbeat → .setHeartbeat
.setHeartbeat(onFlatline, intervalMs)
Heartbeat h; Int i; :: ( -> ), i -> h
Returns a heartbeat instance. A heartbeat instance is a function. Invoke it to keep the heartbeat going. The identifier is typically thump
(see guide).
-
onFlatline
is invoked when/ifthump
is not invoked during an interval. -
intervalMs
sets the time between thump checks.
.clear(heartbeat)
Heartbeat a :: a -> undefined
Destroy a heartbeat instance. Analagous to clearInterval
/clearTimeout
.
Only use clearHeartbeat
if you need to abort a heartbeat before onFlatline
.
Guide
https://github.com/jasonkuhrt/heartbeat/blob/master/test/index.js