Skip to content

Instantly share code, notes, and snippets.

@alex2600
Created June 17, 2019 17:05
Show Gist options
  • Save alex2600/2e9f64f20cd1ecf42c6a6b46cf34c45f to your computer and use it in GitHub Desktop.
Save alex2600/2e9f64f20cd1ecf42c6a6b46cf34c45f to your computer and use it in GitHub Desktop.
Simple Counter Class using a ttl for counts
class TtlCounter {
constructor (ttl) {
this._count = 0
this._ttl = ttl
}
get value () {
return this._count
}
count () {
this._count++
setTimeout(function () {
this._count--
}.bind(this), this._ttl)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment