Created
October 3, 2020 20:05
-
-
Save BashkaMen/ab2672d26ff436245e65c049d6a19172 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inline ( ^ ) f x = f x | |
let debounce time f = | |
let loop = MailboxProcessor.Start ^ fun mailbox -> async { | |
let mutable lastMsg = None | |
while true do | |
let! msg = mailbox.TryReceive(time) | |
match msg with | |
| None when lastMsg.IsSome -> f lastMsg.Value | |
| _ -> () | |
lastMsg <- msg | |
} | |
loop.Post | |
let work x = | |
printfn "%A" x | |
let work = debounce 1000 work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment