Skip to content

JoshWillik/call-once

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Call Once

Limit dangerous function calls.

Install

$ npm install call-once

Usage

// Simple usage
var callOnce = require( 'call-once' )
var wrapped = callOnce( function( n ){
  setupNuclearTestPlant()
  return true
})

wrapped() // => true
wrapped() // => undefined
// Blocking and unblocking wrapped functions
var callOnce = require( 'call-once' )
var setup = callOnce( function( n ){
  setupNuclearTestPlant()
  return true
})

powerPlant.on( 'constructed', function(){
  setup()
})

president.on( 'cancel_project', function(){
  setup.block() // will prevent the function from being called at all
})

president.on( 'changed_mind', function(){
  setup.unblock() // will allow the function to be called again
})

Note: in reality this is more useful for stuff like promise resolutions on a timeout

About

A javascript library to limit a function to one call

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published