async-once
Guarantee a node-style async function is only executed once.
Last updated 3 years ago by phated .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install async-once 
SYNC missed versions from official npm registry.

async-once

NPM version Downloads Build Status AppVeyor Build Status Coveralls Status Gitter chat

Guarantee a node-style async function is only executed once.

Usage

var once = require('async-once');

var count = 0;

var myAsyncFunc = once(function(cb){
  count++;
  cb(null, count);
});

myAsyncFunc(function(err, result){
  assert(result === 1);
});

myAsyncFunc(function(err, result){
  assert(result === 1);
});

assert(count === 1);

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

Current Tags

  • 1.0.1                                ...           latest (3 years ago)

2 Versions

  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (2)
Downloads
Today 0
This Week 2
This Month 3
Last Day 1
Last Week 1
Last Month 2
Dependencies (2)
Dev Dependencies (8)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |