GitBucket
4.23.0
Toggle navigation
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
sample-golang
/
01_hello
Browse code
add channel sample2
master
1 parent
c76eb88
commit
cec73fc3cd5d1c7c0e9158f1701099693cbf88ce
yhornisse
authored
on 9 Oct 2021
Patch
Showing
1 changed file
+20
-0
■
■
■
■
■
goroutine/channel2.go
Ignore Space
Show notes
View
20
■
■
■
■
■
goroutine/channel2.go
0 → 100644
package
main
import
(
"fmt"
"time"
)
func main
()
{
done
:=
make
(
chan int64
)
go func
()
{
for
i
:=
0
;
i
<
5
;
i
++
{
fmt
.
Println
(
i
)
time
.
Sleep
(
1
*
time
.
Second
)
}
done
<-
10
// send
}()
x
:=
<-
done
// receicve
fmt
.
Println
(
x
)
// 10
}
package main import ( "fmt" "time" ) func main() { done := make(chan int64) go func() { for i := 0; i < 5; i++ { fmt.Println(i) time.Sleep(1 * time.Second) } done <- 10 // send }() x := <- done // receicve fmt.Println(x) // 10 }
Show line notes below