npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

@soncodi/signal

2.0.4 • Public • Published

Signal

Build Status Coverage Status Dependency Status npm version

Tiny, typed signal utility for Node.js and browsers

Installation

npm install @soncodi/signal --save

Usage (TypeScript)

import { Signal } from '@soncodi/signal';
 
const signal = new Signal<number>();
 
const cb = (param: number) => {
  console.log(`signal fired ${param}`);
};
 
signal.on(cb);
 
signal.emit(123);
 
signal.off(cb);

Methods

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)

Fires the signal synchronously, triggering any attached handlers with the given arg.

event(arg)

Fires the signal asynchronously, triggering any attached handlers with the given arg. Useful when attaching handlers later in the same event loop turn.

install

npm i @soncodi/signal

Downloadsweekly downloads

24

version

2.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability