Skip to content

Commit

Permalink
fix debounce finalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed May 10, 2024
1 parent c6d06ca commit dbe2b5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-buttons-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-rx/rx": patch
---

fix debounce finalizer
7 changes: 3 additions & 4 deletions packages/rx/src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,17 +1225,16 @@ export const debounce: {
let timeout: number | undefined
let value = get.once(self)
function update() {
timeout = undefined
get.setSelfSync(get.once(self))
}
get.addFinalizer(function() {
if (timeout !== undefined) {
clearTimeout(timeout)
}
timeout && clearTimeout(timeout)
})
get.subscribe(self, function(val) {
value = val
if (timeout) return
setTimeout(update, millis)
timeout = setTimeout(update, millis)
})
return value
})
Expand Down

0 comments on commit dbe2b5d

Please sign in to comment.