- Learn Data Structures and Algorithms with Golang
- Bhagvan Kommadi
- 96字
- 2021-06-24 15:37:51
The ticketIssue method
The ticketIssue method starts and finishes the issuing of a ticket to the passenger. The ticketIssue method invokes the StartTicketIssue and EndTicketIssue methods after Sleep calls for 10 seconds and two seconds. The ticket is issued after the ticket is processed, as shown in the following code:
//ticketIssue starts and ends the ticket issue
func ticketIssue(Queue *Queue) {
for {
// Sleep up to 10 seconds.
time.Sleep(time.Duration(rand.Intn(10000)) * time.Millisecond)
Queue.StartTicketIssue()
fmt.Println("Ticket Issue starts")
// Sleep up to 2 seconds.
time.Sleep(time.Duration(rand.Intn(2000)) * time.Millisecond)
fmt.Println("Ticket Issue ends")
Queue.EndTicketIssue()
}
}