Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chneau/slow
Go package for Debounce and Throttle
https://github.com/chneau/slow
debounce golang lodash throttle underscore
Last synced: about 6 hours ago
JSON representation
Go package for Debounce and Throttle
- Host: GitHub
- URL: https://github.com/chneau/slow
- Owner: chneau
- License: mit
- Created: 2018-08-08T09:39:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-08T14:07:08.000Z (about 6 years ago)
- Last Synced: 2024-06-20T05:14:08.247Z (5 months ago)
- Topics: debounce, golang, lodash, throttle, underscore
- Language: Go
- Size: 3.91 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slow
Go package for Debounce and Throttle functions.
See [stackoverflow answers](https://stackoverflow.com/a/25991510) for more details about what is throttle and debounce.# install
```bash
go get github.com/chneau/slow
```# usage
```go
...
i := 0
fn := func() {
i++
}
options := &slow.Options{
Trailing: true,
Leading: true,
MaxWait: time.Millisecond * 500,
}
// options = nil // can be null, see defaults
throttled := slow.Throttle(fn, time.Millisecond*50, options)
debounced := slow.Debounce(fn, time.Millisecond*50, options)
// the returned functions will be debounced / throttled.
// so some calls will be no-op depending on the options
throttled()
throttled()
...
```# thanks
Thanks to [lodash](https://lodash.com/) from where the implementation comes from.