Skip to content

restrictOnce

Subhajit Sahu edited this page Aug 7, 2022 · 1 revision

Restrict a function to be used only once.

Alternatives: restrict, restrictOnce, restrictBefore, restrictAfter.


function restrictOnce(x)
// x: a function

const xasyncfn = require('extra-async-function');


var count = 0;
var fn = xasyncfn.restrictOnce(x => ++count);
for (var i=0; i<10; ++i)
  fn(i);
count;
// → 1


References

Clone this wiki locally