Skip to content

Instantly share code, notes, and snippets.

@BashkaMen
Created October 3, 2020 20:05
Show Gist options
  • Save BashkaMen/ab2672d26ff436245e65c049d6a19172 to your computer and use it in GitHub Desktop.
Save BashkaMen/ab2672d26ff436245e65c049d6a19172 to your computer and use it in GitHub Desktop.
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