Socket
Socket
Sign inDemoInstall

async-once

Package Overview
Dependencies
2
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-once

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


Version published
Maintainers
2
Weekly downloads
120
increased by12.15%

Weekly downloads

Readme

Source

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

Keywords

FAQs

Last updated on 28 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc