Skip to content

restrictBefore

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

Restrict a function to be used only upto a certain number of calls.

Alternatives: restrict, restrictOnce, restrictBefore, restrictAfter.


function restrictBefore(x, n)
// x: a function
// n: number of calls upto which it is usable

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


var count = 0;
var fn = xasyncfn.restrictBefore(x => ++count, 3);
for (var i=0; i<10; ++i)
  fn(i);
count;
// → 3


References

Clone this wiki locally