- Learn Data Structures and Algorithms with Golang
- Bhagvan Kommadi
- 106字
- 2021-06-24 15:37:51
The passenger method
The passenger methods starts and ends passenger movement to the queue. The passenger method invokes the StartPass method, and the EndPass method ends after sleep calls for 10 seconds and two seconds. The passenger moves into the queue and reaches the ticket counter, as shown in the following code:
//passenger method starts and ends the pass Queue
func passenger(Queue *Queue) {
//fmt.Println("starting the passenger Queue")
for {
// fmt.Println("starting the processing")
// Sleep up to 10 seconds.
time.Sleep(time.Duration(rand.Intn(10000)) * time.Millisecond)
Queue.StartPass()
fmt.Println(" Passenger starts")
// Sleep up to 2 seconds.
time.Sleep(time.Duration(rand.Intn(2000)) * time.Millisecond)
fmt.Println( " Passenger ends")
Queue.EndPass()
}
}