-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix spelling error and some improper demo (#807)
Co-authored-by: zhouzilong.luke <zhouzilong.luke@bytedance.com> Co-authored-by: Joe Chen <jc@unknwon.io>
- Loading branch information
1 parent
e719589
commit dc86a91
Showing
3 changed files
with
14 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
var cnt = 0 | ||
|
||
func main() { | ||
ch1 := make(chan int) | ||
go pump(ch1) // pump hangs | ||
fmt.Println(<-ch1) // prints only 0 | ||
|
||
time.Sleep(time.Second) | ||
fmt.Println(cnt) // prints 1 | ||
|
||
} | ||
|
||
func pump(ch chan int) { | ||
for i := 0; ; i++ { | ||
ch <- i | ||
ch <- i // the channel will be block due to lack of consumer | ||
cnt++ // this code will only execute once | ||
} | ||
} |