Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Synchronous-concurrency/Go/synchronous-concurrency.go
Normal file
32
Task/Synchronous-concurrency/Go/synchronous-concurrency.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
lines := make(chan string)
|
||||
count := make(chan int)
|
||||
go func() {
|
||||
c := 0
|
||||
for l := range lines {
|
||||
fmt.Println(l)
|
||||
c++
|
||||
}
|
||||
count <- c
|
||||
}()
|
||||
|
||||
f, err := os.Open("input.txt")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for s := bufio.NewScanner(f); s.Scan(); {
|
||||
lines <- s.Text()
|
||||
}
|
||||
f.Close()
|
||||
close(lines)
|
||||
fmt.Println("Number of lines:", <-count)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue