async-once
Advanced tools
Comparing version 1.0.0 to 1.0.1
16
index.js
@@ -8,4 +8,4 @@ 'use strict'; | ||
function asyncOnce(fn){ | ||
// our state | ||
function asyncOnce(fn) { | ||
// Our state | ||
var _err; | ||
@@ -15,3 +15,3 @@ var _result; | ||
function worker(work, done){ | ||
function worker(work, done) { | ||
var ctx = work.ctx; | ||
@@ -21,3 +21,3 @@ var initial = work.initial; | ||
function updateState(err, result){ | ||
function updateState(err, result) { | ||
_err = err; | ||
@@ -30,3 +30,3 @@ _result = result; | ||
if(_called){ | ||
if (_called) { | ||
cb(_err, _result); | ||
@@ -41,3 +41,3 @@ done(); | ||
return function(){ | ||
return function() { | ||
var args = slice.call(arguments, 0); | ||
@@ -47,6 +47,6 @@ var work = { | ||
initial: args.slice(0, -1), | ||
cb: args.slice(-1)[0] | ||
cb: args.slice(-1)[0], | ||
}; | ||
if(typeof work.cb !== 'function'){ | ||
if (typeof work.cb !== 'function') { | ||
throw new Error('async-once only works with node-style async functions'); | ||
@@ -53,0 +53,0 @@ } |
{ | ||
"name": "async-once", | ||
"version": "1.0.0", | ||
"description": "Guarantee a node-style async function is only executed once", | ||
"version": "1.0.1", | ||
"description": "Guarantee a node-style async function is only executed once.", | ||
"author": "Gulp Team <team@gulpjs.com> (http://gulpjs.com/)", | ||
"contributors": [ | ||
"Blaine Bublitz <blaine.bublitz@gmail.com>" | ||
], | ||
"repository": "gulpjs/async-once", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">= 0.10" | ||
}, | ||
"main": "index.js", | ||
"files": [ | ||
"LICENSE", | ||
"index.js" | ||
], | ||
"scripts": { | ||
"test": "lab -cvL" | ||
"lint": "eslint index.js test/ && jscs index.js test/", | ||
"pretest": "npm run lint", | ||
"test": "mocha --async-only", | ||
"cover": "istanbul cover _mocha --report lcovonly", | ||
"coveralls": "npm run cover && istanbul-coveralls" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/phated/async-once" | ||
"dependencies": { | ||
"basic-queue": "^1.0.1", | ||
"wrappy": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^1.10.3", | ||
"eslint-config-gulp": "^2.0.0", | ||
"expect": "^1.20.2", | ||
"istanbul": "^0.4.3", | ||
"istanbul-coveralls": "^1.0.3", | ||
"jscs": "^2.4.0", | ||
"jscs-preset-gulp": "^1.0.0", | ||
"mocha": "^3.5.3" | ||
}, | ||
"keywords": [ | ||
@@ -19,17 +46,3 @@ "once", | ||
"time" | ||
], | ||
"author": "Blaine Bublitz <blaine@iceddev.com> (http://iceddev.com/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/phated/async-once/issues" | ||
}, | ||
"homepage": "https://github.com/phated/async-once", | ||
"devDependencies": { | ||
"code": "^1.3.0", | ||
"lab": "^5.3.0" | ||
}, | ||
"dependencies": { | ||
"basic-queue": "^1.0.1", | ||
"wrappy": "^1.0.1" | ||
} | ||
] | ||
} |
@@ -0,6 +1,12 @@ | ||
<p align="center"> | ||
<a href="http://gulpjs.com"> | ||
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png"> | ||
</a> | ||
</p> | ||
# async-once | ||
[![Travis Build Status](https://img.shields.io/travis/phated/async-once/master.svg?label=travis&style=flat-square)](https://travis-ci.org/phated/async-once) | ||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] | ||
Guarantee a node-style async function is only executed once | ||
Guarantee a node-style async function is only executed once. | ||
@@ -30,4 +36,26 @@ ## Usage | ||
## API | ||
### `once(fn)` | ||
Takes a node-style async function (`fn`) to ensure it's only called once. The function should accept a callback as its last parameter which is called with `cb(err, result)`. Returns a function that can be called any number of times but will only execute once. Arguments passed to the returned function will be passed to the `fn`. | ||
## License | ||
MIT | ||
[downloads-image]: http://img.shields.io/npm/dm/async-once.svg | ||
[npm-url]: https://npmjs.com/package/async-once | ||
[npm-image]: http://img.shields.io/npm/v/async-once.svg | ||
[travis-url]: https://travis-ci.org/gulpjs/async-once | ||
[travis-image]: http://img.shields.io/travis/gulpjs/async-once.svg?label=travis-ci | ||
[appveyor-url]: https://ci.appveyor.com/project/gulpjs/async-once | ||
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/async-once.svg?label=appveyor | ||
[coveralls-url]: https://coveralls.io/r/gulpjs/async-once | ||
[coveralls-image]: http://img.shields.io/coveralls/gulpjs/async-once/master.svg | ||
[gitter-url]: https://gitter.im/gulpjs/gulp | ||
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.png |
Sorry, the diff of this file is not supported yet
61
5175
8
52
4
42