Tiny, typed signal utility for Node.js and browsers.
npm install @soncodi/signal



Tiny, typed signal utility for Node.js and browsers. No dependencies.
_Need multiple dynamic events and types? Check out EE (Event Emitter) instead_
``sh`
npm install @soncodi/signal --save
`typescript
import { Signal } from '@soncodi/signal';
// specify callback param type
const signal = new Signal
const cb = (num: number) => console.log('signal', num);
signal.on(cb);
signal.emit(123);
signal.off(cb);
`
#### on(fn)
Attaches a signal handler to be called whenever the signal fires.
#### once(fn)
Attaches a one-time handler which is unbound after it fires the first time.
#### off(fn?)
Detaches one instance of a given handler from the signal. If no handler is provided, detaches all handlers.
#### emit(arg)arg
Fires the signal synchronously, triggering any attached handlers with the given .
#### event(arg)arg`. Useful when attaching handlers later in the same event loop turn.
Fires the signal asynchronously, triggering any attached handlers with the given