Function throttle

Creates a throttled function that calls given function only once every given time. Throttled function takes the same arguments, returns "cached" value of last "real" call to the given function. Time (in ms) can be specified as an array - each "real" call to the function will then pick next value of that array as a time to wait for the next "real" call. This is useful for throttled notifications or auto-retries. Last value of the array will be used if no more values. Returned function also includes cancel property - call it to stop any planned calls (and reset the time array progress) and flush property - call it to immediately run planned call.

You can provide options to specify if function should be invoked immediately on first call to throttled function (leading property) and if it should be called after given time (trailing property).

If (this is default) both leading and trailing property are true then it's required to call throttled function at least twice.