Last active
March 11, 2023 21:58
-
-
Save aliev/3c6bf94389779ecc90df2d2e9aec3f77 to your computer and use it in GitHub Desktop.
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
package main | |
func gen(f int) chan int { | |
// Creating non-buffered channel | |
c := make(chan int) | |
go func() { | |
for i := 0; i < f; i++ { | |
// This part of the code will be blocked until someone will read from c channel. | |
c <- i | |
} | |
// Closing the channel at the end of the iteration | |
close(c) | |
}() | |
// Returns current channel. | |
return c | |
} | |
func main() { | |
gen(10) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment