包详细信息

async-once

gulpjs648MIT2.0.0

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

once, async, callback, one

自述文件

async-once

NPM version Downloads Build Status Coveralls Status

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

更新日志

Changelog

2.0.0 (2022-06-28)

⚠ BREAKING CHANGES

  • Normalize repository, dropping node <10.13 support (#10)

Miscellaneous Chores

  • Normalize repository, dropping node <10.13 support (#10) (7bcae07)