![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
evt-promise
Advanced tools
An event-driven promise-like function wrapper, has a different api through the ES6 Promise
npm install evt-promise --save
If you don’t understand the examples below or you want to see more detailed usage, have a look at this
const evt = require('evt-promise');
//Simple usage
var foo = evt(function() {return true;});
foo.exec(function(value){console.log(value);},function(e) {throw e;}); //Will print true
//Catch errors
var bar = evt(function() {throw new Error('TEST');});
bar.exec(function(v){}, function(e){console.error(e.message);}); //Will print 'TEST' at stderr
//Pass arguments
var baz = evt(function(arg) {return arg;},[true]);
baz.exec(function(value){console.log(value);},function(e) {throw e;}); //Will print true
const evt = require('evt-promise');
//Simple usage
var foo = evt.promiseLike(function() {this.emit('resolved',true)});
foo.then(function(value){console.log(value);})
.catch(function(e) {throw e;}); //Will print true
//Catch errors
var bar = evt.promiseLike(function() {this.emit.('rejected', new Error('TEST'));});
bar.then(function(v){})
.catch(function(e){console.error(e.message);}); //Will print 'TEST' at stderr
//Pass arguments
var baz = evt.promiseLike(function(arg) {this.emit('resolved',arg)},[true]);
baz.then(function(value){console.log(value);})
.catch(function(e) {throw e;}); //Will print true
Warning: If you are using arrow function as the task in any of the examples that uses new Promise-like API, they won't work because you can't inject a this object to an arrow function
const evt = require('evt-promise');
//Change the task
var foo = evt(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 = evt(function(arg) {return arg;},[true]);
bar.args = [false];
bar.exec(function(value){console.log(value);},function(e) {throw e;}); //Will print false not true
const evt = require('evt-promise');
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 = evt(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
FAQs
An event-driven promise-like function wrapper
The npm package evt-promise receives a total of 1 weekly downloads. As such, evt-promise popularity was classified as not popular.
We found that evt-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.