Socket
Socket
Sign inDemoInstall

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 1.0.0 to 1.0.1

14

CHANGES.md
# Changes
## v1.0.0
## 1.0.1
- Convert test cases to Mocha
- Move documentation into README.md
- Move examples into code
## 1.0.0
- New documentation page
- Added link to new project homepage
## v0.4.0
## 0.4.0

@@ -15,8 +21,8 @@ - Named callbacks

## v0.3.1
## 0.3.1
- Fix: Don't pass on undefined values from callbacks
## v0.3.0
## 0.3.0
- Listeners can take an optional function that gets invoked with the callback arguments.

@@ -11,6 +11,6 @@ /*

function ErrorList(errors) {
this.name = 'ErrorList';
var sep = '\n - ';
this.message = 'Multiple callbacks err\'d:' + sep + errors.join(sep);
this.errors = errors;
this.name = 'ErrorList';
var sep = '\n - ';
this.message = 'Multiple callbacks err\'d:' + sep + errors.join(sep);
this.errors = errors;
}

@@ -17,0 +17,0 @@

@@ -10,5 +10,20 @@ /*

var ErrorList = require('./error-list');
var ErrorList = require('./error-list');
var TimeoutError = require('./timeout-error');
function withTimeout(delegate, timeout) {
var timer = setTimeout(function () {
delegate(new TimeoutError());
delegate = null;
}, timeout);
return function (err, value) {
if (delegate) {
clearTimeout(timer);
delegate(err, value);
}
};
}
function listen(initialValues) {

@@ -26,3 +41,3 @@ var values;

var offset = values.length;
var count = 0;
var count = 0;
var called = 0;

@@ -64,15 +79,2 @@ var errList;

function withTimeout(delegate, timeout) {
var timer = setTimeout(function () {
delegate(new TimeoutError());
delegate = null;
}, timeout);
return function (err, value) {
if (delegate) {
clearTimeout(timer);
delegate(err, value);
}
};
}
function listener(name, fn, timeout) {

@@ -82,13 +84,13 @@ assertUnresolved();

timeout = fn;
fn = name;
name = null;
fn = name;
name = null;
} else if (typeof name === 'number') {
timeout = name;
fn = null;
name = null;
fn = null;
name = null;
} else if (typeof fn === 'number') {
timeout = fn;
fn = null;
fn = null;
}
var index = offset + count++;
var index = offset + count++;
var callback = function (err, value) {

@@ -95,0 +97,0 @@ if (fn) {

{
"name" : "listen",
"version" : "1.0.0",
"description" : "Wait for the results of multiple callbacks",
"keywords" : ["callback", "thenable", "timeout", "async", "flow"],
"author" : "Maximilian Antoni (http://maxantoni.de)",
"homepage" : "http://maxantoni.de/projects/listen.js/",
"main" : "./lib/listen.js",
"engines" : {
"node" : ">=0.6"
"name": "listen",
"version": "1.0.1",
"description": "Wait for the results of multiple callbacks",
"keywords": [
"callback",
"thenable",
"timeout",
"async",
"flow"
],
"author": "Maximilian Antoni (http://maxantoni.de)",
"homepage": "http://maxantoni.de/projects/listen.js/",
"main": "./lib/listen.js",
"engines": {
"node": ">=0.10"
},
"scripts" : {
"test" : "make test"
"scripts": {
"watch": "mochify --watch",
"lint": "jslint --edition=latest --color \"**/*.js\"",
"wd": "mochify --wd",
"pretest": "npm run lint",
"test": "mocha && npm run cover",
"cover": "mochify --cover"
},
"repository" : {
"type" : "git",
"url" : "https://github.com/mantoni/listen.js.git"
"repository": {
"type": "git",
"url": "https://github.com/mantoni/listen.js.git"
},
"devDependencies" : {
"utest" : "~0.0.8",
"urun" : "~0.0.6",
"sinon" : "~1.6.0",
"uglify-js" : "~1.2.6",
"autolint" : "~1.0.4",
"phantomic" : "~0.2.0",
"browserify" : ">=2.13 <3",
"consolify" : "~0.3.0"
"devDependencies": {
"jslint": "^0.8.1",
"mocha": "^2.5.3",
"mochify": "^2.18.1",
"sinon": "^1.17.5"
},
"files" : ["lib", "docs", "README.md", "CHANGES.md", "LICENSE"]
"files": [
"lib",
"README.md",
"CHANGES.md",
"LICENSE"
],
"license": "MIT"
}

@@ -1,36 +0,89 @@

# listen.js [![Build Status](https://secure.travis-ci.org/mantoni/listen.js.png?branch=master)](http://travis-ci.org/mantoni/listen.js)
# listen.js
Wait for the results of multiple callbacks
[![Build Status]](https://travis-ci.org/mantoni/listen.js)
[![SemVer]](http://semver.org)
[![License]](https://github.com/mantoni/listen.js/blob/master/LICENSE)
Homepage: <http://maxantoni.de/projects/listen.js/>
A tiny library to wait for the results of multiple callbacks. For node and the
browser.
Repository: <https://github.com/mantoni/listen.js>
## Install
---
This will install the `listen` module in your current project and add it to the
`dependencies`:
## Install with NPM
```
npm install listen
npm install listen --save
```
## Download for browsers
## Usage
Standalone browser package are here: <http://maxantoni.de/listen.js/>
```js
var listen = require('listen');
You can also use npm and bundle it with your application using
[Browserify](http://browserify.org).
var listener = listen();
var callbackA = listener();
var callbackB = listener();
## Development
/*
* Do async stuff with callbacks.
*
* Callbacks follow the Node.js convention. They expect an error or null as
* the first argument and an optional value as the second:
*
* Fail: callback(new Error('ouch!'));
* Return: callback(null, 'some return value');
*/
listener.then(function (err, values) {
/*
* err - 1) null if no callback received an error
* 2) the error of the callback that received an error
* 3) an error with name ErrorList wrapping multiple errors
*
* values - The non-undefined return values from all callbacks in order of
* callback creation, also exposing names callbacks (see API)
*/
});
```
Here is what you need:
# API
- `npm install` will install all the dev dependencies
- `make` does all of the following
- `make lint` lint the code with JSLint
- `make test` runs all unit tests in Node
- `make browser` generates a static web page at `test/all.html` to run the tests in a browser.
- `make phantom` runs all tests in a the headless [Phantom.JS](http://phantomjs.org). Make sure you have `phantomjs` in your path.
Start with `var listen = require('listen')`, then use the `listen` function to
create listeners. Use the listeners to create callbacks.
To build a browser package containing the merged / minified scripts run `make package`.
- `listen([values])`: Creates and returns a new listener function. If `values`
are given, it must be an array with initial values.
- `listener([name][, func][, timeout])`: Creates a new callback associated with
the listener. Throws if called after `then`. All arguments are optional and
can be combined.
- `name` exposes the return value of the callback on the values object
under that name.
- `func` gets invoked with `(err, value)` when the callback is invoked.
- `timeout` calls the callback with a `TimeoutError` after the timeout.
- `listener.then(func)`: Invokes the given function once all callbacks where
invoked. If none of the callbacks had errors, the first argument is `null`,
otherwise it's an `Error`. The second argument is the values array in order
of callback creation. Can only be called once.
- `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`.
## Compatibility
The `listen` has 100% coverage and runs in these environments:
- Node 0.10, 0.12, 4.3 & 6.3
- IE 9, 10, 11
- Firefox
- Chore
- PhantomJS
## License
MIT
[Build Status]: http://img.shields.io/travis/mantoni/listen.js.svg
[SemVer]: http://img.shields.io/:semver-%E2%9C%93-brightgreen.svg
[License]: http://img.shields.io/npm/l/listen.svg
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