// Creates an infinite stream of integers counting up from 1
func createCounter() <-chan int {
result := make(chan int)
go func() {
var n int
for {
n++
result <- n
}
}()
return result
}
Submitted by admin on 2016, December 12, 4:49 PM. golang
// Creates an infinite stream of integers counting up from 1
func createCounter() <-chan int {
result := make(chan int)
go func() {
var n int
for {
n++
result <- n
}
}()
return result
}
« 2025年05月 » | ||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |