Corout

Addons
451 Downloads Last Updated: Jul 16, 2013 Game Version: 2.3

This library has been created to keep out of the watchdog easily. Instead of having to write the whole coroutine mechanic each time you have performance issues, you can use this. It permit to create a coroutine in a couple of lines.

To use it, just call corout(YourFunction) and it will start a coroutine running YourFunction automatically. You have to call corout.check() sometimes in your function to verify that the watchdog isn't about to cut of you addon.

It is recommended to add a label to all your corouts in order to be safe with others addons and your own addon when you use multiples corouts together. In addition, you're allowed to pass as much parameters as you wish after those ones. You may get something like corout(MyFunction, "Corout MyLabel", MyArg1, MyArg2, ...). You can also define another time remaining limit before watchdog alarm if you want to (default is 0.03).

Here is an example :

function example(arg1, arg2)
    for foo, foo2 in pairs(arg) do
        arg2[foo] = foo2
        -- do something here

        corout.check()      -- check the watchdog state
    end
end

corout(example, "Corout AddonIdentifier", arg1, arg2)

If you have any suggestion or feedback, i would be glad to hear it.

Comments

Posts Quoted: