SHARE
TWEET

Untitled

a guest Oct 21st, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt";"time"
  5. )
  6.  
  7. func main() {
  8.     theMine := [5]string{"rock", "ore", "ore", "rock", "ore"}
  9.     oreChannel := make(chan string)
  10.     minedOreChan := make(chan string)
  11.    
  12.     // Finder
  13.     go func(mine [5]string) {
  14.      for _, item := range mine {
  15.       if item == "ore" {
  16.        oreChannel <- item //send item on oreChannel
  17.       }
  18.      }
  19.     }(theMine)
  20.    
  21.     // Ore Breaker
  22.     go func() {
  23.      for i := 0; i < 3; i++ {
  24.       foundOre := <-oreChannel //read from oreChannel
  25.       fmt.Println("From Finder: ", foundOre)
  26.       minedOreChan <- "minedOre" //send to minedOreChan
  27.      }
  28.     }()
  29.    
  30.     // Smelter
  31.     go func() {
  32.      for i := 0; i < 3; i++ {
  33.       minedOre := <-minedOreChan //read from minedOreChan
  34.       fmt.Println("From Miner: ", minedOre)
  35.       fmt.Println("From Smelter: Ore is smelted")
  36.      }
  37.     }()
  38.    
  39.     <-time.After(time.Second * 5) // Again, you can ignore this
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top