The _.after
function from lodash returns a function that will invoke the provided function after it has been called n
or more times. This can be useful for delaying the execution of a function until it has been called a certain number of times.
Here's an example of how to use _.after
:
index.tsx290 chars17 lines
In this example, myFunc
is a function that will be called after it has been called 3 times. We use _.after
to create a new function myFuncAfter
that will call myFunc
after it has been called 3 times. We then call myFuncAfter
three times, and on the third call myFunc
is finally invoked.
Note that if we were to call myFuncAfter
a fourth time, myFunc
would be called again. That's because myFunc
needs to be called 3 or more times before it will be invoked by myFuncAfter
.
gistlibby LogSnag