Gitart
10/30/2016 - 10:28 AM

Go chain

Go chain

package main

import (
	"fmt"
	"time"
)

func main() {
	lChan := make(chan int, 5)
	lDone := make(chan bool)
	
	go func() {
		for i := 0; i < 3; i++ {
			fmt.Println("Received: ", <-lChan)
		}
		close(lDone)
	}()
	
	for i := 0; i < 10; i++ {
		select {
		case lChan <- i:
			fmt.Println("Sent: ", i)
		case <- time.After(time.Minute):
			//TODO: Here goes the code to handle what happens if the buffer is full 
			//or nobody is currently receiving data
		}
		
	}
	
	<- lDone
	
	fmt.Println("Finished!")
}