Created
April 4, 2018 14:30
-
-
Save packrat386/2c9bd61033126da6d7b79dca8b40fe33 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
var access func() int | |
func init() { | |
i := 0 | |
t := time.After(100 * time.Millisecond) | |
access = func() int { | |
select { | |
case <-t: | |
i++ | |
t = time.After(100 * time.Millisecond) | |
return i | |
default: | |
return i | |
} | |
} | |
} | |
func main() { | |
for { | |
fmt.Println(access()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment