@kjk1/

gobook channels signal

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.035632724948453154","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKKQoKLy8gOnNob3cgc3RhcnQKZnVuYyB3b3JrZXIoY2ggY2hhbiBpbnQsIGNoUXVpdCBjaGFuIHN0cnVjdHt9KSB7Cglmb3IgewoJCXNlbGVjdCB7CgkJY2FzZSB2IDo9IDwtY2g6CgkJCWZtdC5QcmludGYoIkdvdCB2YWx1ZSAlZFxuIiwgdikKCQljYXNlIDwtY2hRdWl0OgoJCQlmbXQuUHJpbnRmKCJTaWduYWxsZWQgb24gcXVpdCBjaGFubmVsLiBGaW5pc2hpbmdcbiIpCgkJCWNoUXVpdCA8LSBzdHJ1Y3R7fXt9CgkJCXJldHVybgoJCX0KCX0KfQpmdW5jIG1haW4oKSB7CgljaCwgY2hRdWl0IDo9IG1ha2UoY2hhbiBpbnQpLCBtYWtlKGNoYW4gc3RydWN0e30pCglnbyB3b3JrZXIoY2gsIGNoUXVpdCkKCWNoIDwtIDMKCWNoUXVpdCA8LSBzdHJ1Y3R7fXt9CgoJLy8gd2FpdCB0byBiZSBzaWduYWxsZWQgYmFjayBieSB0aGUgd29ya2VyCgk8LWNoUXVpdAp9CgovLyA6c2hvdyBlbmQ="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import (
	"fmt"
)

// :show start
func worker(ch chan int, chQuit chan struct{}) {
	for {
		select {
		case v := <-ch:
			fmt.Printf("Got value %d\n", v)
		case <-chQuit:
			fmt.Printf("Signalled on quit channel. Finishing\n")
			chQuit <- struct{}{}
			return
		}
	}
}
func main() {
	ch, chQuit := make(chan int), make(chan struct{})
	go worker(ch, chQuit)
	ch <- 3
	chQuit <- struct{}{}

	// wait to be signalled back by the worker
	<-chQuit
}

// :show end