-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transducers): update re-exports, extract throttleTime() into own…
… file
- Loading branch information
1 parent
8e5204d
commit 45d6bc6
Showing
3 changed files
with
28 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Transducer } from "../api"; | ||
import { throttle } from "./throttle"; | ||
|
||
/** | ||
* Time-based version of `throttle`. Ignores any new values in the | ||
* `delay` interval since the last accepted value. | ||
* | ||
* **Only to be used in async contexts and NOT with `transduce` directly.** | ||
* | ||
* Also see: `@thi.ng/rstream` and `@thi.ng/csp` packages. | ||
* | ||
* @param delay | ||
*/ | ||
export function throttleTime<T>(delay: number): Transducer<T, T> { | ||
return throttle<T>( | ||
() => { | ||
let last = 0; | ||
return () => { | ||
const t = Date.now(); | ||
return t - last >= delay ? (last = t, true) : false; | ||
}; | ||
}); | ||
} |
This file contains 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