Created
June 17, 2019 17:05
-
-
Save alex2600/2e9f64f20cd1ecf42c6a6b46cf34c45f to your computer and use it in GitHub Desktop.
Simple Counter Class using a ttl for counts
This file contains hidden or 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
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