Socket
Book a DemoInstallSign in
Socket

@rainder/callbacks

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rainder/callbacks

callbacks with a timeout

latest
Source
npmnpm
Version
0.3.2
Version published
Maintainers
1
Created
Source

Callbacks

Callback implementation with native Promises

Example

const co = require('co');
const Callbacks = require('@rainder/callbacks');

const callbacks = new Callbacks();

co(function *() {
  //define data to work with
  const ID = '10432';
  const DATA = 'data1';
  
  //create a callback
  const promise = callbacks.create(ID);
  
  setTimeout(function () {
    callbacks.getCallback(ID).resolve(DATA);
  }, 100);
  const result = yield promise;
  
  result.should.equals(DATA); //true
}).catch(err => console.error(err.stack));

Callbacks

new Callbacks(): Callbacks

static Callbacks.create(): Callbacks

create(id: String, [timeout: Number = 30000]): Promise

getCallback(id: String): Callback

Callback

new Callback(id: String, timeout: Number, onDestroy: Function)

resolve(data)

reject(err)

destroy()

Keywords

callback

FAQs

Package last updated on 13 Feb 2017

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