This is a creation in Article, where the information may have evolved or changed.
Package Main
Import (
"Log"
"Math/rand"
"Time"
)
Func uploadnetvaluefile (done chan bool) {
Using random functions to simulate processing time for different files
r: = Rand. New (Rand. Newsource (time. Now (). Unixnano ()))
x: = R.INTN (20)
Log. Println ("Uploadnetvaluefile:", x)
Time. Sleep (time. Second * time. Duration (x))
Log. Println ("Uploadnetvaluefile OK")
Done <-True
}
Func uplaodsalefarefile (done chan bool) {
Using random functions to simulate processing time for different files
r: = Rand. New (Rand. Newsource (time. Now (). Unixnano () + 10))
x: = R.INTN (20)
Log. Println ("Uplaodsalefarefile:", x)
Time. Sleep (time. Second * time. Duration (x))
Log. Println ("Uplaodsalefarefile OK")
Done <-True
}
Func Main () {
T1: = time. Now ()
Tasknum: = 2
Done: = Make (chan bool, tasknum)
//Simulate when the file was generated
Time. Sleep (time. Second * 1)
Log. Println ("Create Netvalue file!")
//Concurrent execution
Go Uploadnetvaluefile (done)
//Simulate when the file was generated
Time. Sleep (time. Second * 1)
Log. Println ("Create Salefare file!")
//Concurrent execution
Go Uplaodsalefarefile (done)
//wait for all concurrent finishes
Func () {
For I: = 0; i < Tasknum; i++ {
Log. Println (<-done)
}
}()
t2: = time. Now ()
Log. Printf ("Time-consuming:%d\n", T2. Sub (t1))
}