diff --git a/README.md b/README.md index 9d0db74..5b2d4a8 100644 --- a/README.md +++ b/README.md @@ -578,9 +578,18 @@ Hello
PAUSED
Hello3
+# 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
-- Write multi:newThreadedUpdater(name,skip)
- Test for unknown bugs
**Don't find these useful tbh, I will document them eventually though** - Document Triggers
diff --git a/multi/all.lua b/multi/all.lua index dd6baa7..5e264f4 100644 --- a/multi/all.lua +++ b/multi/all.lua @@ -15,3 +15,4 @@ require("multi.threading.loop") require("multi.threading.process") require("multi.threading.step") require("multi.threading.tstep") +require("multi.threading.updater") \ No newline at end of file diff --git a/multi/threading/all.lua b/multi/threading/all.lua index b28e005..fe05cb4 100644 --- a/multi/threading/all.lua +++ b/multi/threading/all.lua @@ -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") diff --git a/multi/threading/updater.lua b/multi/threading/updater.lua new file mode 100644 index 0000000..d117038 --- /dev/null +++ b/multi/threading/updater.lua @@ -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