promotional bannermobile promotional banner

ThreadLite

Abandoned
Provides a lightweight threading library.
ThreadLite is a lightweight threading library intended to be used by other addons. Usage is simple. Create a lightweight thread (a lua coroutine) by calling:
ThreadLite.Create(func, funcArgs, onSuccessFunc, onFailFunc)
Lightweight threads are fire-and-forget. Func will be invoked with the passed in funcArgs (they will be unpacked). If your coroutine succeeds (ie, there are no lua errors), onSuccessFunc will be invoked with the threadlite argument and any values returned by func (again, unpacked). If your function fails, onFailFunc will be called for you, again with the threadlite object as the first parameter and the error text as the second parameter. It's easier to learn by doing, so here's an example of an Addon that counts raid attendance every minute (for example, to update DKP values) using ThreadLite. In MyMod.Lua, you might have a function:
function MyMod.GetCurrentRaidAttendance()
  local status = {}
  for i=1, MAX_RAID_MEMBERS  do
    local name, _, _, _, _, _, _, online, _, _, _ = GetRaidRosterInfo(raidIndex);
    if name then
      status[name] = online
    end
  end
  return status
You want to throttle this check so that it's being called no more than once a minute. Using ThreadLite, you could do the following:
function MyMod.UpdateDkpFromAttendance()
  while GetNumRaidMembers()  > 0 do
    TP.Sleep(60) -- seconds to sleep
    local status = MyMod.GetCurrentRaidAttendance()
    table.foreach(status,
      function(who, online)
        if online then
          MyMod.AwardDkp(who, 1)
        end
      end
    )
  end
end
Then, in your event handler for joining a raid, you would have some code that looks like this:
ThreadLite.Create(MyMod.UpdateDkpFromAttendance, {})
And your function is off and running, and will continue running until you leave the raid. ThreadLite also offers a handful of syncronization primitives, in addition to being able to Sleep. There's also a Barrier function to wait until the specified number of game events have passed (useful for waiting on Auction House Results to return), and a Throttle function (currently misnamed) to ensure that your function isn't spending too much time updating. The syncronization methods all take an optional abortfunc parameter to end their waiting period. For example, if your mod is waiting for auction house results to return, an abortfunc would check and see if the auction frame still exists and is being shown. This mod is required by McDkp.

The ThreadLite Team

profile avatar
  • 4
    Projects
  • 3.7K
    Downloads

More from _ForgeUser2672656

  • McDkp project image

    McDkp

    • 1.7K
    • Addons

    A dkp auction framework with pluggable rulesets.

    • 1.7K
    • January 21, 2010
    • Addons
    • +2
  • McFilter project image

    McFilter

    • 458
    • Addons

    Library for addon writers to ensure that a callback is only called once, even though WoW spams the message many times.

    • 458
    • January 21, 2010
    • Addons
    • +1
  • UpdateSet project image

    UpdateSet

    • 935
    • Addons

    UpdateSet

    • 935
    • June 9, 2009
    • Addons
  • McDkp project image

    McDkp

    • 1.7K
    • Addons

    A dkp auction framework with pluggable rulesets.

    • 1.7K
    • January 21, 2010
    • Addons
    • +2
  • McFilter project image

    McFilter

    • 458
    • Addons

    Library for addon writers to ensure that a callback is only called once, even though WoW spams the message many times.

    • 458
    • January 21, 2010
    • Addons
    • +1
  • UpdateSet project image

    UpdateSet

    • 935
    • Addons

    UpdateSet

    • 935
    • June 9, 2009
    • Addons