Advertisement
samuelask

Untitled

Dec 19th, 2024 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. local message_queue = {}
  2.  
  3. local function process_messages()
  4. print("Coroutine started")
  5. while true do
  6. local message = table.remove(message_queue, 1)
  7. if message then
  8. print("Processing:", message[1])
  9. else
  10. print("No messages, yielding...")
  11. coroutine.yield()
  12. end
  13. end
  14. end
  15.  
  16. -- Create the coroutine
  17. local message_processor = coroutine.create(process_messages)
  18.  
  19. -- Add a message to the queue
  20. table.insert(message_queue, { "modem_message", "worker1", 1234, "result", { key = "value" } })
  21.  
  22. -- Resume the coroutine
  23. print("Resuming coroutine...")
  24. local success, err = coroutine.resume(message_processor)
  25. print("Coroutine status after resume:", coroutine.status(message_processor))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement