bep / debounce Goto Github PK
View Code? Open in Web Editor NEWA debouncer written in Go.
License: MIT License
A debouncer written in Go.
License: MIT License
Example:
d := New(1 * time.Second)
for i := 0; i < 10; i++ {
d(func () {
println("called")
})
time.Sleep(900 * time.Millisecond)
}
// Nothing output.
Expected:
"called" should be printed 8~9 times.
If the debouncing period elapses before the first invocation, the operation goes haywire. Inspired by this library I have implemented https://github.com/angadn/debounce
However, as the API is different, I am not issuing a PR here.
debounce's New
function changed its signature. This release was tagged as a semver'd v1 release but this signature change is API incompatible. This API change should have been tagged as v2.0.0
.
Dependency managers (eg dep / go modules) may choose upgrade debounce from v1.1.0 to v1.2.0. Code that relies on the v1.1.0's New
will now fail to compile.
An example break is with Hugo. Hugo v0.54.0 depends on debounce and was released with debounce v1.1.0. This works fine if I start a project and install Hugo.
tristan@dashie:~/go/src/example.com/foo$ go version
go version go1.12.1 linux/amd64
tristan@dashie:~/go/src/example.com/foo$ export GO111MODULE=on
tristan@dashie:~/go/src/example.com/foo$ go mod init
go: creating new go.mod: module example.com/foo
tristan@dashie:~/go/src/example.com/foo$ go run github.com/gohugoio/hugo
Total in 0 ms
Error: Error building site: open /home/tristan/go/src/example.com/foo/content: no such file or directory
exit status 255
But if I update dependencies, debounce v1.2.0 will come in and Hugo breaks.
tristan@dashie:~/go/src/example.com/foo$ go get -u github.com/bep/debounce
tristan@dashie:~/go/src/example.com/foo$ go run github.com/gohugoio/hugo
# github.com/gohugoio/hugo/commands
../../../pkg/mod/github.com/gohugoio/[email protected]/commands/commandeer.go:146:26: assignment mismatch: 3 variables but debounce.New returns 1 values
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.