Last active
April 18, 2019 20:30
-
-
Save yakuter/2d141f1867e535e35f2bf0d97cde7dfe to your computer and use it in GitHub Desktop.
Go Channels Örneği
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 | |
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