Quantcast
Download
(4 Kb)
Download
Updated: 11/09/18 01:07 PM
Pictures
File Info
Compatibility:
Murkmire (4.2)
Wolfhunter (4.1)
Updated:11/09/18 01:07 PM
Created:09/02/18 10:37 AM
Monthly downloads:5,290
Total downloads:7,239
Favorites:21
MD5:
4.2
LibAsync  Popular! (More than 5000 hits)
Version: 1.8.1
by: votan [More]
Description
Read this article of the Wiki.

API
local async = LibStub("LibAsync")
local task = async:Create(name)

The signature of FuncOfTask is:
Code:
local function(task)
end
-- Get the current context, if you are within a FuncOfTask or nil.
Code:
function async:GetCurrent()
-- Create an interruptible task context.
Code:
function async:Create(name)
-- Resume the execution context.
Code:
task:Resume()
-- Suspend the execution context and allow to resume anytime later.
Code:
function task:Suspend()
-- Interupt and fully stop the execution context. Can be called from outside to stop everything.
Code:
function task:Cancel()
-- Run the given FuncOfTask in your task context execution.
Code:
function task:Call(funcOfTask)
-- Continue your task context execution with the given FuncOfTask after the previous as finished.
Code:
function task:Then(funcOfTask)
-- Start an interruptible for-loop.
Code:
function task:For(from, to, step)
function task:For(pairs(tbl))
function task:For(ipairs(tbl))
-- Execute the async-for with the given step-function. The parameters of the step-function are those you would use in your for body.
Code:
function task:Do(func)
The signature if func is function(index) or function(key, value)
If you return async.BREAK within func, it will break the loop.

-- Suspend the execution of your task context for the given delay in milliseconds and then call the given FuncOfTask to continue.
Code:
function task:Delay(delay, funcOfTask)
-- Stop the delay created by Delay
Code:
function task:StopTimer()
-- Set a FuncOfTask as a final handler. Called even if something went wrong in your context.
Code:
function task:Finally(funcOfTask)
-- Set a FuncOfTask as an error handler. Called if something went wrong in your context.
Code:
function task:OnError(funcOfTask)

Example 1
Lua Code:
  1. local async = LibStub("LibAsync")
  2.  
  3. local task = async:Create("example1")
  4.  
  5. local i=1
  6. local function Hello() d("Hello") end
  7. local function World() d("World") end
  8.  
  9. task:Call(function(task)
  10.  d(i)
  11.  task:Call(Hello):Then(World)
  12.  i = i + 1
  13.  return i<1000
  14. end):Then(function() d("end") end)
Example 2
Lua Code:
  1. local async = LibStub("LibAsync")
  2.  
  3. local task = async:Create("example2")
  4.  
  5. local start = GetGameTimeMilliseconds()
  6.  
  7. task:For (1,1000):Do(function(index) d(index) end):Then(
  8. function()
  9.   task:For (pairs({"a", "b"})):Do(function(key, value) d(key,value)
  10.     task:For (ipairs({"c", "d"})):Do(function(key, value) d(key,value)  end)
  11.  end)
  12. end):For(1001,1010):Do(function(index) d(index) end):Then(function(task)
  13.   df("%ims", GetGameTimeMilliseconds() - start)
  14. end)
Remarks
  • Yes, using LibAsync increases the total duration of the process for a better framerate.
  • Lua code can cause hiccups and (micro-)freezes, but has nothing to do the lag.
  • Lua can cause crash to bug report, if too much memory is allocated within one frame. (e.g. string operations) => Spread you code over time.
  • Lua can cause kick to login, if too much server request are done within a time range. (e.g. map pings/bug/sell/ignore, etc.) => Spread you code over time.
version 1.8.1:
- Work without LibStub as well.

version 1.8.0:
- API update "Murkmire".
- Adjustment to scheduler calculation: Reduce allowed-time after a burst even if loops still running.
- Change from GetGameTimeMilliseconds to GetGameTimeSeconds, which has in fact more precision. Thanks to @zsban.
Optional Files (0)


Archived Files (2)
File Name
Version
Size
Author
Date
1.8.0
6kB
votan
10/06/18 02:10 PM
1.7
6kB
votan
09/02/18 10:37 AM


Post A Reply Comment Options
Unread 10/26/18, 11:22 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 459
File comments: 1039
Uploads: 27
Re: Error at crafting station, when deconstructing:

Originally Posted by Kestrelator
Code:
user:/AddOns/LibAsync/LibAsync.lua:35: user:/AddOns/RulebasedInventory/Modules/ActionExecution.lua:286: operator + is not supported for nil + number
stack traceback:
user:/AddOns/RulebasedInventory/Modules/ActionExecution.lua:286: in function 'ExecuteAction'
|caaaaaa<Locals> status = true, priority = 1, bagId = 6, slotIndex = 5, stackCountChange = -1, executionCounter = 0, cacheId = 2, rowIndex = 5, bagCache = tbl, itemInstanceIdLookup = tbl, row = tbl, lookup = tbl, delay = 0, rowUpdate = tbl </Locals>|r
(tail call): ?
[C]: in function 'pcall'
user:/AddOns/LibAsync/LibAsync.lua:21: in function 'DoCallback'
|caaaaaa<Locals> job = tbl, callstackIndex = 1 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:49: in function 'DoJob'
|caaaaaa<Locals> job = tbl, index = 1 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:100: in function 'async.Scheduler'
|caaaaaa<Locals> start = 2220.4016113281, runTime = 2220.4111899, cpuLoad = 0.0094038718748379 </Locals>|r
(tail call): ?
stack traceback:
[C]: in function 'error'
user:/AddOns/LibAsync/LibAsync.lua:35: in function 'DoCallback'
|caaaaaa<Locals> job = tbl, callstackIndex = 1, success = false, shouldContinue = "user:/AddOns/RulebasedInven..." </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:49: in function 'DoJob'
|caaaaaa<Locals> job = tbl, index = 1 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:100: in function 'async.Scheduler'
|caaaaaa<Locals> start = 2220.4016113281, runTime = 2220.4111899, cpuLoad = 0.0094038718748379 </Locals>|r
(tail call): ?
Hello Kestrelator,

the error occurs in RulebasedInventory. LibAsync is in this case just the library used.
__________________
@votan73 (EU - megaserver)
Report comment to moderator  
Reply With Quote
Unread 10/26/18, 10:04 AM  
Kestrelator

Forum posts: 0
File comments: 20
Uploads: 0
Error at crafting station, when deconstructing:

Code:
user:/AddOns/LibAsync/LibAsync.lua:35: user:/AddOns/RulebasedInventory/Modules/ActionExecution.lua:286: operator + is not supported for nil + number
stack traceback:
user:/AddOns/RulebasedInventory/Modules/ActionExecution.lua:286: in function 'ExecuteAction'
|caaaaaa<Locals> status = true, priority = 1, bagId = 6, slotIndex = 5, stackCountChange = -1, executionCounter = 0, cacheId = 2, rowIndex = 5, bagCache = tbl, itemInstanceIdLookup = tbl, row = tbl, lookup = tbl, delay = 0, rowUpdate = tbl </Locals>|r
(tail call): ?
[C]: in function 'pcall'
user:/AddOns/LibAsync/LibAsync.lua:21: in function 'DoCallback'
|caaaaaa<Locals> job = tbl, callstackIndex = 1 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:49: in function 'DoJob'
|caaaaaa<Locals> job = tbl, index = 1 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:100: in function 'async.Scheduler'
|caaaaaa<Locals> start = 2220.4016113281, runTime = 2220.4111899, cpuLoad = 0.0094038718748379 </Locals>|r
(tail call): ?
stack traceback:
[C]: in function 'error'
user:/AddOns/LibAsync/LibAsync.lua:35: in function 'DoCallback'
|caaaaaa<Locals> job = tbl, callstackIndex = 1, success = false, shouldContinue = "user:/AddOns/RulebasedInven..." </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:49: in function 'DoJob'
|caaaaaa<Locals> job = tbl, index = 1 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:100: in function 'async.Scheduler'
|caaaaaa<Locals> start = 2220.4016113281, runTime = 2220.4111899, cpuLoad = 0.0094038718748379 </Locals>|r
(tail call): ?
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: