Last active
April 18, 2019 07:49
-
-
Save yakuter/20bb6af37f1f1c3084a6976587c6c2bf to your computer and use it in GitHub Desktop.
Go Channel Gönderici ve Alıcı Fonksiyon Örneği
This file contains 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) | |
var bulunan string | |
// Bulucu | |
go func(dizi []string) { | |
for _, kahraman := range dizi { | |
sender(ilkKanalim, kahraman) | |
time.Sleep(time.Second) | |
} | |
}(kahramanlar) | |
// Alıcı | |
go func() { | |
for i := 0; i < 4; i++ { | |
mesaj := receiver(bulunan, ilkKanalim) | |
fmt.Println("Alıcı: Bulucudan " + mesaj + " alındı") | |
} | |
}() | |
<-time.After(time.Second * 5) | |
} | |
func sender(channel chan<- string, message string) { | |
channel <- message | |
} | |
func receiver(message string, channel <-chan string) string { | |
message = <-channel | |
return message | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment