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

listen

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

listen - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

.travis.yml

25

lib/listen.js

@@ -36,7 +36,21 @@ /**

function assertUnresolved() {
if (handler) {
throw new Error("Cannot be called after then");
}
}
function pushError(e) {
if (!errList) {
errList = [];
}
errList.push(e);
}
function listener() {
assertUnresolved();
var index = offset + count++;
return function (err, value) {
if (err) {
listener.err(err);
pushError(err);
}

@@ -53,2 +67,3 @@ if (value !== undefined) {

listener.push = function push(value) {
assertUnresolved();
values[offset + count] = value;

@@ -58,7 +73,5 @@ offset++;

listener.err = function err(err) {
if (!errList) {
errList = [];
}
errList.push(err);
listener.err = function err(e) {
assertUnresolved();
pushError(e);
};

@@ -65,0 +78,0 @@

{
"name" : "listen",
"version" : "0.1.1",
"version" : "0.1.2",
"description" : "Wait for the results of multiple callbacks",

@@ -5,0 +5,0 @@ "author" : "Maximilian Antoni (http://maxantoni.de)",

@@ -1,4 +0,63 @@

listen.js
=========
# listen.js
Wait for the results of multiple callbacks
Wait for the results of multiple callbacks.
[![Build Status](https://secure.travis-ci.org/mantoni/listen.js.png?branch=master)](http://travis-ci.org/mantoni/listen.js)
## Install
```
npm install listen
````
## Usage
```js
var listen = require('listen');
var listener = listen();
var callbackA = listener();
var callbackB = listener();
// ... do async stuff with callbacks
listener.then(function (err, values) {
/*
* err - 1) null if no callback err'd
* 2) the error of the callback that err'd
* 3) an error with name ErrorList wrapping multiple errors
*
* values - The non-undefined return values from all callbacks in order of
* callback creation
*/
});
```
## API
`listen()` - creates a new listener.
`listen(values)` - creates a new listener with initial values. The given argument must be an array.
`listener()` - creates a new callback associated with the listener. Throws if called after `then`.
`listener.then(func)` - invokes the given function once all callbacks where invoked. Throws if already called.
`listener.push(value)` - pushes a value to the internal values array. Throws if called after `then`.
`listener.err(error)` - adds an error to the internal error list. Throws if called after `then`.
## Run tests
```
make
```
## Compile for browsers
This requires [nomo.js](https://github.com/mantoni/nomo.js).
```
make compile
```

@@ -32,2 +32,12 @@ /**

assert.deepEqual(spy.firstCall.args[0].errors, ['a', 'b']);
},
'should throw if called after then': function () {
this.listener.then(function () {});
var self = this;
assert.throws(function () {
self.listener.err();
}, /^Error: Cannot be called after then$/);
}

@@ -34,0 +44,0 @@

@@ -27,2 +27,12 @@ /**

assert.equal(typeof callback, 'function');
},
'should throw if called after then': function () {
this.listener.then(function () {});
var self = this;
assert.throws(function () {
self.listener();
}, /^Error: Cannot be called after then$/);
}

@@ -29,0 +39,0 @@

@@ -44,6 +44,15 @@ /**

sinon.assert.calledWith(spy, null, ['a', 'b']);
},
'should throw if called after then': function () {
this.listener.then(function () {});
var self = this;
assert.throws(function () {
self.listener.push(1);
}, /^Error: Cannot be called after then$/);
}
});

Sorry, the diff of this file is not supported yet

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