Channel multiple messages?
Posted: Mon Dec 17, 2018 11:04 am
So the Wiki documentation on thread channels are quite confusing. I have ran into a situation where I need to push information into a channel without halting the channel, so I use Channel:push(value). However, in the event that the thread is ready to push another value into the same channel before it is pulled, I want the old value to not be processed on the other side of the channel.
I tried doing it this way:
But I feel like there is a small amount of time between pop() and push() in which problems could arise.
LOVE2D's wiki documentation makes it very confusing as to if there are multiple messages, or if a channel can only have one message present at a time. If there actually is a queue, where there are multiple messages waiting to be pop'ed, why is there no method to fetch messages out-of-order in the queue (like if I wanted the second message from the queue)? Honestly, I can see this go both ways--a channel having only one message at a time, and a channel having a queue.
I tried doing it this way:
Code: Select all
if(Channel:getCount() > 0)then
Channel:pop()
end
Channel:push(value)
LOVE2D's wiki documentation makes it very confusing as to if there are multiple messages, or if a channel can only have one message present at a time. If there actually is a queue, where there are multiple messages waiting to be pop'ed, why is there no method to fetch messages out-of-order in the queue (like if I wanted the second message from the queue)? Honestly, I can see this go both ways--a channel having only one message at a time, and a channel having a queue.