the time in milliseconds after which a trailing (pending) call to the function gets resolved if no other calls are made during that time interval.
you would definitely want this to be some value greater than delta_time_ms, otherwise it will be weird because if this value is smaller, then trailing_time_ms
will become the "effective" throttling time interval, but also one that always resolved later rather than immediately.
the time interval in milliseconds for throttling
the function to be throttled
Optional
rejection_value: REJif a rejection value is provided, then old unresolved pending promises will be rejected with the given value, when a new call to the throttled function is made within the trailing_time_ms waiting period
a function (that takes arguments intended for fn
) that returns a Promise
to the value of fn
if it is resolved (i.e. not throttled or when trailing),
otherwise if throttled, then that promise will either be never be resolved, or rejected based on if a rejection_value was provided.
a throttle function, similar to throttle, that also insures that the final call (aka trailing call) made to the throttled function always resolves eventually.
this is useful in cases where it is of utmost importance that the throttled function is called one last time with before a prolonged delay.
the following visual illustration shows the difference between the regular throttle, and throttleAndTrail functions:
throttleAndTrail
:fn
throttled withtrailing_time_ms = 1500
, anddelta_time_ms = 1000
. as you can see below, the trailing calls to the throttled function do get resolved eventuallythrottle
:fn
throttled withdelta_time_ms = 1000
. as you can see below, the final call to the throttled function gets rejected, because it was called too quickly