+ Reply to Thread
Results 1 to 3 of 3

Thread: Events, Coroutines & the Watchdog - Help Needed

  1. #1
    Soulwalker
    Join Date
    Jan 2015
    Posts
    15

    Default Events, Coroutines & the Watchdog - Help Needed

    Good evening,

    I'm trying to wrap my head around how to stop the Watchdog from killing my function calls. Here's some example code:

    Code:
    local list = {}  -- let's pretend it's populated
    
    function ParseList()
    local num = 300 -- yield at 300 iterations local i = 1 while #list > 0 do
    -- do work here, subtracting from "list" i = i + 1 if i % num == 0 then
    coroutine.yield()
    end
    end
    end Command.Event.Attach(Command.Slash.Register("ParseList"), function (h, p)
    ParseList()
    -- implement coroutine.create() / resume() code here end, "Slash command")
    It's obvious that this code won't work as the yield() will blow up because it's not being called by a coroutine. If I DO implement coroutine code in the location commented out above, ParseList() properly yields a few times, then it's the anonymous "function (h, p)" that's killed off by the watchdog, not the ParseList() function.

    I'm pretty sure that I need to fire the ParseList() function by attaching it to an event so it has its own time to live, but I'd need to call that event repeatedly, which makes me believe that I'll run into the same issue of having THAT code being killed off by the watchdog.

    If there are any obvious answers or solutions to this, I'm all ears. Thanks in advance!

    Hugh
    Last edited by hughball; 02-13-2015 at 11:19 PM.

  2. #2
    Soulwalker
    Join Date
    Jan 2015
    Posts
    15

    Default

    Typical of me to ask a question out loud, then have some success at solving my own problem.

    So I did something like this:

    Code:
    local eventHandle, eventTable = Utility.Event.Create("myAddon", "ParseList")
    local myCoRo = nil
    
    local function ParseList
    -- do work and yield appropriately (see above)
    end local function DispatchParseList
    if myCoRo == nil then
    myCoRo = coroutine.create(ParseList)
    else
    if coroutine.status(myCoRo) == "dead" then
    myCoRo = nil
    else
    coroutine.resume(myCoRo)
    end
    end Command.Event.Attach(Command.Slash.Register("parseList"), function (h,p) eventHandle() end, "Slash command") Command.Event.Attach(Event.myAddon.ParseList, DispatchParseList, "DispatchParseList()")
    That slash command is what's killing me. I need to somehow get that called on a fast timer... I'm not sure. But at least it's not crashing anymore.

  3. #3
    Soulwalker
    Join Date
    Jan 2015
    Posts
    15

    Default

    Man, old resources are killing me. I'd been trying to attach to System.Update.Begin rather than Event.System.Update.Begin and wondered if maybe I'd been doing it wrong.

    Well that ends that - I'm off to the races again. Hopefully this thread will help someone else.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts