Skip to content

Instantly share code, notes, and snippets.

@yakuter yakuter/main.go
Last active Apr 18, 2019

Embed
What would you like to do?
Go Channels Örneği
package main
import (
"fmt"
"time"
)
func main() {
kahramanlar := []string{"Marvel", "Flash", "Thanos", "Flash"}
ilkKanalim := make(chan string)
// Bulucu
go func(dizi []string) {
for _, kahraman := range dizi {
ilkKanalim <- kahraman // Kanala gönderiliyor
time.Sleep(time.Second)
}
}(kahramanlar)
// Alıcı
go func() {
for i := 0; i < 4; i++ {
bulunan := <-ilkKanalim // Kanaldan alınıyor
fmt.Println("Alıcı: Bulucudan " + bulunan + " alındı")
}
}()
<-time.After(time.Second * 5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.