Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local message_queue = {}
- local function process_messages()
- print("Coroutine started")
- while true do
- local message = table.remove(message_queue, 1)
- if message then
- print("Processing:", message[1])
- else
- print("No messages, yielding...")
- coroutine.yield()
- end
- end
- end
- -- Create the coroutine
- local message_processor = coroutine.create(process_messages)
- -- Add a message to the queue
- table.insert(message_queue, { "modem_message", "worker1", 1234, "result", { key = "value" } })
- -- Resume the coroutine
- print("Resuming coroutine...")
- local success, err = coroutine.resume(message_processor)
- print("Coroutine status after resume:", coroutine.status(message_processor))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement