Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

evt-promise

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evt-promise

An event-driven promise-like function wrapper

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

evt-promise

Build Status Build Status Coverage Status

An event-driven promise-like function wrapper, has a different api through the ES6 Promise

Install

npm install evt-promise

Usage

BASIC:

const async = require('evt-async');

//Simple usage
var foo = async(function() {return true;});
foo.exec(function(value){console.log(value);},function(e) {throw e;}); //Will print true

//Catch errors
var bar = async(function() {throw new Error('TEST');});
bar.exec(function(v){}, function(e){console.error(e.message);}); //Will print 'TEST' at stderr

//Pass arguments
var baz = async(function(arg) {return arg;},[true]);
baz.exec(function(value){console.log(value);},function(e) {throw e;}); //Will print true

Advanced - Change the task that you want to run, Change the arguments that you want to pass to the task function:

const async = require('evt-async');

//Change the task
var foo = async(function() {return true});
foo.task = function() {
	return false;
}
foo.exec(function(value){console.log(value);},function(e) {throw e;}); //Will print false, not true

//Change the arguments
var bar = async(function(arg) {return arg;},[true]);
bar.args = [false];
bar.exec(function(value){console.log(value);},function(e) {throw e;}); //Will print false not true

Advanced - Emit custom events in the task and handle it

const async = require('evt-async');

var fn = function() {
	this.emit('custom','custom event'); //The this object is an instance of eventemitter2, injected by the apply() function
	return 'hello custom';
};

var resHandler = function(value) {
	console.log(value);
};

var rejHandler = function(e) {
	throw e;
};

var foo = async(fn)

foo.event.on('custom', function(value) {console.log(value);});

foo.exec(resHandler,rejHandler); //Will print 'custom event' and then 'hello coustom'

Warning: If you use arrow function as the task, this example won't work because you cannot inject a this object to an arrow function

Keywords

FAQs

Package last updated on 06 Feb 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc