Nice article - but unfortunately a bit wrong: https://www.code-partners.com/tnotifyevent-debouncing-in-delphi/

Nice article - but unfortunately a bit wrong: https://www.code-partners.com/tnotifyevent-debouncing-in-delphi/

The title says debounce but he explains, shows and implements throttle.

There is a link that explains both:
https://css-tricks.com/debouncing-throttling-explained-examples/

TL'DR
Throttle limits the occurence of events to only one per given time interval.
Debounce only fires one event after a given time of inactivity.

These operations and many others are part of the reactive extension spec and will be part of a future Spring4D release that brings RX to Delphi.

Comments

  1. Stefan Glienke​, are you alone to develop Sprind4D ? I really enjoy this wonderful library !

    ReplyDelete
  2. Thanks, I got some help from Honza Rameš and other people in the past and mostly Baoquan Zuo who started that project several years ago ;)

    It's hard to find excellent developers with enough time that are able to bear with me ;)

    ReplyDelete
  3. Stefan Glienke I could bear with you, but I don't have enough time ;-)

    Excellent... you are really asking way too much ;-)

    ReplyDelete
  4. FWIW this is the code for a delayed search while the user is typing into an edit using Spring.Reactive:

    TObservable.FromEventPattern(Edit1, 'OnChange')
    .Throttle(1000)
    .ObserveOn(TScheduler.MainThread)
    .Subscribe(
    procedure(const args: TNotifyEventArgs)
    begin
    Caption := Format('searching for %s', [TEdit(args.Sender).Text]);
    end);

    ReplyDelete
  5. Very nice! These days I was, just for fun, trying to implement this behavior by following the http://reactivex.io specs.

    Maybe you can make this an independent library and add Delphi language as official in http://reactivex.io/languages.html

    ReplyDelete
  6. Rafael Dipold Certainly not independent because it uses some things from Spring.pas and Collections.

    Once it is done (still a lot of work, most likely for months) I will add Delphi to their list for sure.

    ReplyDelete
  7. Wow, Both of the two are new concept to me, thanks Stefan, and I'm looking forward to the said new features for spring4d!

    ReplyDelete

Post a Comment