March 2019
Intermediate to advanced
336 pages
9h 9m
English
The New method on Queue initializes message, queuePass, and queueTicket with nil values. The make method creates a Queue with a chan integer parameter, as follows:
// New method initializes queuefunc (queue *Queue) New() { queue.message = make(chan int) queue.queuePass= make(chan int) queue.queueTicket= make(chan int) }
In the following code example, the Go routine handles selecting the message based on the type of message and the respective queue to process it:
go func() { var message int for { select { case message = <-queue.message: switch message { case messagePassStart: queue.waitPass++ case messagePassEnd: queue.playPass = false case messageTicketStart: queue.waitTicket++ case messageTicketEnd: queue.playTicket = false ...Read now
Unlock full access