<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, October 17, 2005, 7:02 AM -->
<!-- MuClient version 3.67 -->

<!-- Plugin "Command_Queue" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Command_Queue"
   author="Nick Gammon"
   id="685b994664e3afced386d332"
   language="Lua"
   purpose="Queues up commands and sends one every second"
   date_written="2005-10-17 06:47:09"
   requires="3.61"
   version="1.0"
   >

</plugin>


<!--  Script  -->


<script>
<![CDATA[

-- queue of things to send
queue = {}

-- called by a timer to resume a thread
function wait_timer_resume (name)
  assert (coroutine.resume (thread))
end -- function wait_timer_resume 

function worker_thread (thread)

  while true do
  
    coroutine.yield () -- wait a second
  
    if table.getn (queue) > 0 then
       Send (table.remove (queue, 1))
    end -- of having an entry in the table

  end  -- of infinite while loop
  
end -- function worker_thread 


function OnPluginInstall ()

  -- timer will be called every second to kick things along
  status = AddTimer ("wait_timer", 0, 0, 1, "",
            timer_flag.Enabled + 
            timer_flag.Temporary + timer_flag.Replace, 
            "wait_timer_resume")
  assert (status == error_code.eOK, error_desc [status])

  -- start up worker thread
  thread = coroutine.create (worker_thread)
  assert (coroutine.resume (thread, thread))

end -- function OnPluginInstall

function OnPluginConnect ()

  queue = {}    -- start afresh when connecting

end -- function OnPluginConnect

function QueueIt (what)

  table.insert (queue, what)  -- insert into our queue

end -- function QueueIt 


]]>
</script>


</muclient>
