Go
5
Вклад в тег
package main
import (
"fmt"
"time"
)
var numChan chan int
var outChan chan string
func main() {
input := []int{3, 1, 8, 7, 5, 9, 2}
numChan = make(chan int)
outChan = make(chan string)
go func() {
labelsReceiver(outChan)
}()
time.Sleep(time.Millisecond) // Так попытался убедиться, что получатель стартует первым. Не знаю как правильно сделать.
go func() {
labelsEmitter(numChan, outChan)
}()
for _, num := range input {
fmt.Println(num)
numChan <- num
}
close(numChan)
close(outChan)
}
func labelsEmitter(numbers chan int, outChan chan string) {
fmt.Println("go labelsEmitter")
//out := make(chan string, 3)
//defer close(out)
for num := range numbers {
time.Sleep(time.Millisecond * 200)
str := fmt.Sprintf("Number %d", num)
outChan <- str
}
return
}
func labelsReceiver(labelChanRcv <-chan string) {
fmt.Println("go labelsReceiver")
for label := range labelChanRcv {
fmt.Println("label", label)
}
}
err := fmt.Errorf("access denied: %w", ErrPermission)
...
if errors.Is(err, ErrPermission)