@kjk1/

gobook channels range

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6135693701437148","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKKQoKLy8gOnNob3cgc3RhcnQKCmZ1bmMgZm9vKGNoIGNoYW4gaW50KSB7CgljaCA8LSAxCgljaCA8LSAyCgljbG9zZShjaCkKfQoKZnVuYyBtYWluKCkgewoJY2ggOj0gbWFrZShjaGFuIGludCkKCWdvIGZvbyhjaCkKCWZvciBuIDo9IHJhbmdlIGNoIHsKCQlmbXQuUHJpbnRsbihuKQoJfQoJZm10LlByaW50bG4oImNoYW5uZWwgaXMgbm93IGNsb3NlZCIpCn0KCi8vIDpzaG93IGVuZA=="},"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
package main

import (
	"fmt"
)

// :show start

func foo(ch chan int) {
	ch <- 1
	ch <- 2
	close(ch)
}

func main() {
	ch := make(chan int)
	go foo(ch)
	for n := range ch {
		fmt.Println(n)
	}
	fmt.Println("channel is now closed")
}

// :show end