Elmish.WPF icon indicating copy to clipboard operation
Elmish.WPF copied to clipboard

Throttling particular message type

Open xperiandri opened this issue 3 months ago • 5 comments

High-level description I've created such throttling function

[<AutoOpen>]
module Dispatching =

    open System
    open Elmish
    open R3

    let asDispatchWrapper<'msg>
        (configure: Observable<'msg> -> Observable<'msg>)
        (dispatch: Dispatch<'msg>)
        : Dispatch<'msg> =
        let subject = new Subject<_>()
        (subject |> configure).Subscribe dispatch |> ignore
        fun msg -> async.Return(subject.OnNext msg) |> Async.Start

    let throttle<'msg> =
        /// Ignores elements from an observable sequence which are followed by another element within a specified relative time duration.
        let throttle  (dueTime:TimeSpan) (source:Observable<'Source>): Observable<'Source> =
            source.ThrottleLast(dueTime)
        throttle (TimeSpan.FromMilliseconds 500)
        |> asDispatchWrapper<'msg>

But it throttles all the messages which causes input data to be missed. How would you suggest to fix that?

Expected or desired behavior All messages are throttled

Actual behavior Only a particular message type is throttled

xperiandri avatar Apr 18 '24 15:04 xperiandri