Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created May 29, 2019 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriqaaq/8f153995f28ee513393ea58d0c7aaf1f to your computer and use it in GitHub Desktop.
Save arriqaaq/8f153995f28ee513393ea58d0c7aaf1f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
type Receiver struct{
doneCh chan bool
wg sync.WaitGroup
}
func (r *Receiver) Stop() {
close(r.doneCh)
r.wg.Wait()
}
func (r *Receiver) Start() {
go func(){
for{
select{
case <- r.doneCh:
fmt.Println("Closed Start 1")
r.wg.Done()
return
}
}
}()
go func(){
for{
select{
case <- r.doneCh:
fmt.Println("Closed Start 2")
r.wg.Done()
return
}
}
}()
}
func NewReceiver() *Receiver {
n:= &Receiver{
doneCh : make(chan bool),
}
n.wg.Add(2)
return n
}
func main() {
rec:=NewReceiver()
rec.Start()
rec.Stop()
fmt.Println("Bye, playground")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment