Piorjade 2 Posted March 24, 2017 Share Posted March 24, 2017 Soo I was kinda bored doing basically nothing when I thought about making an OS for OC, which I wanted to do for a long time now. I got pretty far, considering that I'm pretty new to OC, up to the point where it is supposed to start up background "services" at the same time. I didn't know that computer.pullSignal / event.pull doesn't let a coroutine yield (I copied the event and keyboard api over to my OS because I thought I didn't need to rewrite these things on my own) so I quickly had to think of a solution and came up with this. Functions Currently I made it usable for normal OpenOS so that everyone can use it: createTasklist(): returns a table with premade functions which will basically contain all of your tasks createTask(tasklist [tasklist table], name [string], func [string], env [environment table], disableG [bool]): creates a task using the given name, sets its environment to the given one , modifies event.pull (yes you need to have the event library available) and adds a sleep([number]) function which is the same as os.sleep() but only for the task quit([name]): if no name is given, it stops running all the tasks. if a name is given, it stops only the specified task runAll(tasklist): This is the main function. It is the main loop which iterates through every task until it gets a quit signal tasklist:clearLog(): clears the errorLog table and the log table inside the tasklist table tasklist:killTask([name]): Kills the task with the given name. However, I don't recommend this one and you should use quit([name]) for that Short explanation Basically it modifies event.pull (and adds sleep() if you need that) so that it doesn't pull an event, but adds a filter and lets the coroutine yield until it gets an event. (or it yields until it gets the event with the given filters OR until it times out) Which allows us to quickly iterate through every coroutine over and over again. Coroutines which don't yield for a while get killed but while they're not yielding they are basically pausing the whole computer until they time out. Code Pastebin Quote Link to post Share on other sites
Gorzoid 10 Posted March 24, 2017 Share Posted March 24, 2017 Just so you know, event.pull calls coroutine.yield so really modifying event.pull is unnecessary, just coroutine.resume the task with each signal and event lib will do the rest of the work. Not exactly correct, looks like machine.lua also messes with coroutine table in order to correctly sandbox it. Shame, it'd be so simple otherwise. Quote Link to post Share on other sites