Added ThreaderUpdater
Added the threadedupdater module and updated the all.lua to reflect the new additions!
This commit is contained in:
parent
018d1bd36f
commit
6b3e0b5f9b
11
README.md
11
README.md
@ -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>
|
||||
|
||||
@ -15,3 +15,4 @@ require("multi.threading.loop")
|
||||
require("multi.threading.process")
|
||||
require("multi.threading.step")
|
||||
require("multi.threading.tstep")
|
||||
require("multi.threading.updater")
|
||||
@ -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")
|
||||
|
||||
32
multi/threading/updater.lua
Normal file
32
multi/threading/updater.lua
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user