🚀 Socket Launch Week 🚀 Day 2: Introducing Repository Labels and Security Policies.Learn More
Socket
Sign inDemoInstall
Socket

async-once

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-once

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

2.0.0
latest
Source
npm
Version published
Weekly downloads
218
-18.05%
Maintainers
2
Weekly downloads
 
Created
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

once

FAQs

Package last updated on 28 Jun 2022

Did you know?

Socket

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