You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// return a factory function mapping input values to "throttled" Commands that only dispatch if enough time passed
234
+
fun(value: 'value)->
235
+
[fun dispatch ->
236
+
letnow= System.DateTime.UtcNow
237
+
238
+
// If the interval has elapsed since the last execution, dispatch the message
239
+
if now - lastDispatch >= System.TimeSpan.FromMilliseconds(float interval)then
240
+
lastDispatch <- now
241
+
dispatch(fn value)
242
+
]
243
+
244
+
/// <summary>
245
+
/// Creates a Command factory that dispatches the most recent message in a given interval - even if delayed.
246
+
/// This makes it similar to <seecref="throttle"/> in that it rate-limits the message dispatch
247
+
/// and similar to <seecref="debounce"/> in that it guarantees the last message (within the interval or in total) is dispatched.
248
+
/// Helpful for scenarios where you want to throttle, but cannot risk losing the last message to throttling
249
+
/// - like the last progress update that completes a progress.
250
+
/// Note that this function creates an object with internal state and is intended to be used per Program or longer-running background process
251
+
/// rather than once per message in the update function.
252
+
/// </summary>
253
+
/// <paramname="interval">The minimum time interval between two consecutive Command executions in milliseconds.</param>
254
+
/// <paramname="fn">A function that maps a factory input value to a message for dispatch.</param>
255
+
/// <returns>
256
+
/// A Command factory function that maps an input value to a "buffered throttle" Command which dispatches the most recent message (mapped from the value)
257
+
/// if the minimum time interval has elapsed since the last Command execution; otherwise, it does nothing.
0 commit comments