Elmish.WPF
Elmish.WPF copied to clipboard
Throttling particular message type
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