Skip to content

Instantly share code, notes, and snippets.

@aliev
Last active March 11, 2023 21:58
Show Gist options
  • Save aliev/3c6bf94389779ecc90df2d2e9aec3f77 to your computer and use it in GitHub Desktop.
Save aliev/3c6bf94389779ecc90df2d2e9aec3f77 to your computer and use it in GitHub Desktop.
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