You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

once

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

once

Run a function exactly one time

1.4.0
latest
Version published
Weekly downloads
53M
-13.35%
Maintainers
1
Weekly downloads
 
Created

What is once?

The 'once' npm package is a utility that allows you to ensure a function can only be called once. It is useful for preventing duplicate initialization, handling setup tasks that should only run a single time, or ensuring a callback is only executed once in response to an event or the resolution of a Promise.

What are once's main functionalities?

Ensuring a function is only called once

This feature is used to wrap a function so that it can only be executed once. Subsequent calls to the function will have no effect, and the original return value will be returned.

const once = require('once');
const myFunction = once(() => {
  console.log('This will only be logged once.');
});

myFunction(); // logs 'This will only be logged once.'
myFunction(); // does nothing

Other packages similar to once

FAQs

Package last updated on 06 Sep 2016

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