Added ThreaderUpdater

Added the threadedupdater module and updated the all.lua to reflect the new additions!
This commit is contained in:
Ryan 2017-06-06 16:45:23 -04:00
parent 018d1bd36f
commit 6b3e0b5f9b
4 changed files with 44 additions and 1 deletions

View File

@ -578,9 +578,18 @@ Hello</br>
PAUSED</br>
Hello3</br>
# ThreadedUpdater
```lua
-- Works the same as a regular updater!
require("multi.all")
multi:newThreadedUpdater("Test",10000):OnUpdate(function(self)
print(self.pos)
end)
multi:mainloop()
```
# TODO (In order of importance)
- Write the wiki stuff</br>
- Write multi:newThreadedUpdater(name,skip)</br>
- Test for unknown bugs</br>
**Don't find these useful tbh, I will document them eventually though**
- Document Triggers</br>

View File

@ -15,3 +15,4 @@ require("multi.threading.loop")
require("multi.threading.process")
require("multi.threading.step")
require("multi.threading.tstep")
require("multi.threading.updater")

View File

@ -1,5 +1,6 @@
require("multi.threading.step")
require("multi.threading.tstep")
require("multi.threading.updater")
require("multi.threading.alarm")
require("multi.threading.loop")
require("multi.threading.event")

View File

@ -0,0 +1,32 @@
require("multi.threading")
function multi:newThreadedUpdater(name,skip)
local c=self:newTBase()
c.Type='updaterThread'
c.pos=1
c.skip=skip or 1
function c:Resume()
self.rest=false
end
function c:Pause()
self.rest=true
end
c.OnUpdate=self.OnMainConnect
c.rest=false
c.updaterate=0
c.restRate=.75
multi:newThread(name,function(ref)
while true do
if c.rest then
thread.sleep(c.restRate) -- rest a bit more when a thread is paused
else
for i=1,#c.func do
c.func[i](c)
end
c.pos=c.pos+1
thread.skip(c.skip)
end
end
end)
self:create(c)
return c
end