Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
co-events
Advanced tools
Readme
Listeners can be anything that co supports viz. promises, thunks, generators, arrays or objects..
var events, fs, read;
events = new CoEvents;
fs = require('fs');
read = function(filename) {
return function(cb) {
return fs.readFile(filename, cb);
};
};
events.on('readFile', function*(filename) {
return callback(null, yield read(filename));
});
return events.emit('readFile', 'LICENSE');
Good old EventEmitter style functions.
var events, fs;
events = new CoEvents;
fs = require('fs');
events.on('readFile', function(filename) {
return callback(null, fs.readFileSync(filename));
});
return events.emit('readFile', 'LICENSE');
Listener called when event emitted.
var events;
events = new CoEvents;
events.on('event', function*() {
return callback(null);
});
return events.emit('event');
Arguments sent by emit are applied to listener.
var events;
events = new CoEvents;
events.on('wait', function*(time) {
yield wait(time);
return callback(null);
});
return events.emit('wait', 500);
RemoveListener can remove attached listeners.
var events, fn;
events = new CoEvents;
fn = function*() {
return 'Hello';
};
events.on('hello', fn);
events.removeListener('hello', fn);
assert.equal(false, events.emit('hello'));
return callback(null);
Events registered using .once are removed once they are fired.
var events;
events = new CoEvents;
events.once('hello', function*() {
return 'Hello';
});
events.emit('hello');
assert.equal(false, events.emit('hello'));
return callback(null);
.off is an alias of .removeListener and .trigger is an alias of .emit.
var events, fn;
events = new CoEvents;
fn = function*() {
return 'Hello';
};
events.on('hello', fn);
events.trigger('hello');
events.off('hello', fn);
assert.equal(false, events.trigger('hello'));
return callback(null);
FAQs
Wrapper for EventEmitter for using coroutines.
The npm package co-events receives a total of 1 weekly downloads. As such, co-events popularity was classified as not popular.
We found that co-events 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.