Download
(5 Kb)
Download
Updated: 04/29/23 09:26 AM
Pictures
File Info
Compatibility:
Necrom (9.0.0)
Scribes of Fate (8.3.5)
Updated:04/29/23 09:26 AM
Created:09/02/18 10:37 AM
Monthly downloads:21,676
Total downloads:1,965,317
Favorites:1,021
MD5:
LibAsync  Popular! (More than 5000 hits)
Version: 2.3.4
by: votan [More]
Description
Read this article of the Wiki.

API
local async = 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.

-- Start an interruptible while-loop.
Code:
function task:While(func):Do(doFunc)
As long as func returns true, doFunc and func will be called again.

-- Start an once per frame wait loop.
Code:
function task:WaitUntil(func)
Until func returns true, the function will be called again in the next frame. Keep the check condition simple. For example, checking a flag variable set by an event.

-- 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)
Delay will suspend the exceution immediately, no matter there in the chain it is used. For delaying at chain position use:
Code:
function task:ThenDelay(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 = 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 = 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)
Example 3
Lua Code:
  1. local async = LibAsync
  2.  
  3. local i = 0
  4. async:While(function() return i<100 end):Do(function()
  5.   d(i)
  6.   i = i+1
  7. end)
Example 4
Lua Code:
  1. local async = LibAsync
  2. local time = GetGameTimeSeconds()+10
  3. async:WaitUntil(function()
  4.   return GetGameTimeSeconds()>=time
  5. end):Then(function()
  6.   d("end")
  7. end)
Example 5: Nested calls.
Lua Code:
  1. local async = LibAsync
  2.  
  3. async:Call(function(task)
  4.   d("a")
  5.   task:Call(function(task)
  6.     d("b")
  7.     task:Call(function(task)
  8.       d("c")
  9.     end)
  10.   end)
  11. end):Then(function(task)
  12.   d("d")
  13.   task:Call(function(task)
  14.     d("e")
  15.     task:Call(function(task)
  16.       d("f")
  17.     end)
  18.   end)
  19. end)
Output:
a
b
c
d
e
f

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/buy/sell/ignore, etc.) => Spread you code over time.
version 2.3.4:
- Update for "Necrom".
- No LibStub support.

version 2.3.2:
- Fixed issue with nested "WaitUntil".

version 2.3.1:
- Forgot to remove return in "ThenDelay".

version 2.3.0:
- Fixed execution order issue, if operation are added ourside a running task.
- Add new operation "ThenDelay".

version 2.2.1:
- Update to API 100033 "Markarth".

version 2.2.0:
- Update to API 100032 "Stonethorn".
- New async functions: While and WaitUntil.

version 2.1.0: Register scheduler as late as possible to take count to all actions not using LibAsync.

version 2.0.2:
- Update to API 100029 "Dragonhold".

version 2.0.1:
- Update to API 100028 "Scalebreaker".

version 2.0.0:
- API bump 100027 "Elsweyr".
- Need to go to 2.0 because of the version check of LibStub.

version 1.10.0:
- API bump 100027 "Elsweyr".
- Use of LibStub is optional.

version 1.9.0:
- Update to API 100026 "Wrathstone".
- For V-Sync off/G-Sync the minimum target framerate is 80.

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 (14)
File Name
Version
Size
Uploader
Date
2.3.2
5kB
votan
01/16/21 09:02 AM
2.3.1
5kB
votan
12/19/20 12:13 PM
2.3.0
5kB
votan
12/19/20 09:41 AM
2.2.1
5kB
votan
11/01/20 08:58 AM
2.2.0
5kB
votan
07/31/20 01:48 PM
2.1.0
5kB
votan
12/13/19 02:49 PM
2.0.2
5kB
votan
10/03/19 04:39 AM
2.0.1
5kB
votan
07/29/19 02:17 PM
2.0.0
5kB
votan
05/15/19 01:16 PM
1.10.0
5kB
votan
05/04/19 01:36 PM
1.9.0
4kB
votan
02/23/19 10:15 AM
1.8.1
4kB
votan
11/09/18 01:07 PM
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 03/14/24, 11:48 AM  
thatlaurachick

Forum posts: 0
File comments: 109
Uploads: 0
Re: Error - started around 7pm Pacific on 3/11

Theses errors are almost constant now. I've reinstalled LibAsync but they just don't stop. I can't turn off LibAsync without losing essential addons like MM and WW.

Before you ask: YES I've reinstalled cleanly, YES I update with MInion multiple times a day, YES I've tried turning addons off and on again.
I use gamepad ui for accessibility reasons.

These errors seem to be tied to "pink" status in LibHistorie. Bad thing is I have 1 guild that cannot pull trader history from ZOS. At most I have 3 days worth, but today it cannot pull at all.

Originally Posted by thatlaurachick
Will post to LibHistorie and MM as well

user:/AddOns/LibAsync/LibAsync.lua:299: operator < is not supported for number < nil
stack traceback:
user:/AddOns/LibAsync/LibAsync.lua:299: in function 'asyncForWithStep'
user:/AddOns/LibAsync/LibAsync.lua:327: in function 'tasko'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryProcessingRequest.lua:47: in function 'GuildHistoryProcessingRequest:StartProcessing'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:372: in function 'GuildHistoryCacheCategory:ProcessNextRequest'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:350: in function 'GuildHistoryCacheCategory:QueueProcessingRequest'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryEventListener.lua:203: in function 'GuildHistoryEventListener:Start'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryLegacyEventListener.lua:338: in function 'GuildHistoryLegacyEventListener:Start'
user:/AddOns/MasterMerchant/Libs/LibGuildStore/LGS_LibHistoire.lua:141: in function 'internal:SetupListener'
user:/AddOns/MasterMerchant/Libs/LibGuildStore/LGS_LibHistoire.lua:225: in function 'func'
/EsoUI/Libraries/Globals/globalapi.lua:263: in function '(anonymous)'
Last edited by thatlaurachick : 03/14/24 at 12:20 PM.
Report comment to moderator  
Reply With Quote
Unread 03/14/24, 12:43 PM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 578
File comments: 1678
Uploads: 40
Re: Re: Error - started around 7pm Pacific on 3/11

Originally Posted by thatlaurachick
Theses errors are almost constant now. I've reinstalled LibAsync but they just don't stop. I can't turn off LibAsync without losing essential addons like MM and WW.

Before you ask: YES I've reinstalled cleanly, YES I update with MInion multiple times a day, YES I've tried turning addons off and on again.
I use gamepad ui for accessibility reasons.

These errors seem to be tied to "pink" status in LibHistorie. Bad thing is I have 1 guild that cannot pull trader history from ZOS. At most I have 3 days worth, but today it cannot pull at all.

Originally Posted by thatlaurachick
Will post to LibHistorie and MM as well

user:/AddOns/LibAsync/LibAsync.lua:299: operator < is not supported for number < nil
stack traceback:
user:/AddOns/LibAsync/LibAsync.lua:299: in function 'asyncForWithStep'
user:/AddOns/LibAsync/LibAsync.lua:327: in function 'tasko'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryProcessingRequest.lua:47: in function 'GuildHistoryProcessingRequest:StartProcessing'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:372: in function 'GuildHistoryCacheCategory:ProcessNextRequest'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:350: in function 'GuildHistoryCacheCategory:QueueProcessingRequest'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryEventListener.lua:203: in function 'GuildHistoryEventListener:Start'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryLegacyEventListener.lua:338: in function 'GuildHistoryLegacyEventListener:Start'
user:/AddOns/MasterMerchant/Libs/LibGuildStore/LGS_LibHistoire.lua:141: in function 'internal:SetupListener'
user:/AddOns/MasterMerchant/Libs/LibGuildStore/LGS_LibHistoire.lua:225: in function 'func'
/EsoUI/Libraries/Globals/globalapi.lua:263: in function '(anonymous)'
That is an issue of LibHistoire. ZOS renamed the history manager.
Last edited by votan : 03/14/24 at 12:43 PM.
Report comment to moderator  
Reply With Quote
Unread 03/14/24, 02:03 PM  
thatlaurachick

Forum posts: 0
File comments: 109
Uploads: 0
Re: Re: Re: Error - started around 7pm Pacific on 3/11

Ok thank you for answering. I'll keep posting there.
Originally Posted by votan
Originally Posted by thatlaurachick
Theses errors are almost constant now. I've reinstalled LibAsync but they just don't stop. I can't turn off LibAsync without losing essential addons like MM and WW.

Before you ask: YES I've reinstalled cleanly, YES I update with MInion multiple times a day, YES I've tried turning addons off and on again.
I use gamepad ui for accessibility reasons.

These errors seem to be tied to "pink" status in LibHistorie. Bad thing is I have 1 guild that cannot pull trader history from ZOS. At most I have 3 days worth, but today it cannot pull at all.

Originally Posted by thatlaurachick
Will post to LibHistorie and MM as well

user:/AddOns/LibAsync/LibAsync.lua:299: operator < is not supported for number < nil
stack traceback:
user:/AddOns/LibAsync/LibAsync.lua:299: in function 'asyncForWithStep'
user:/AddOns/LibAsync/LibAsync.lua:327: in function 'tasko'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryProcessingRequest.lua:47: in function 'GuildHistoryProcessingRequest:StartProcessing'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:372: in function 'GuildHistoryCacheCategory:ProcessNextRequest'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:350: in function 'GuildHistoryCacheCategory:QueueProcessingRequest'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryEventListener.lua:203: in function 'GuildHistoryEventListener:Start'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryLegacyEventListener.lua:338: in function 'GuildHistoryLegacyEventListener:Start'
user:/AddOns/MasterMerchant/Libs/LibGuildStore/LGS_LibHistoire.lua:141: in function 'internal:SetupListener'
user:/AddOns/MasterMerchant/Libs/LibGuildStore/LGS_LibHistoire.lua:225: in function 'func'
/EsoUI/Libraries/Globals/globalapi.lua:263: in function '(anonymous)'
That is an issue of LibHistoire. ZOS renamed the history manager.
Report comment to moderator  
Reply With Quote
Unread 04/03/24, 10:28 AM  
Magic Charmer

Forum posts: 15
File comments: 51
Uploads: 0
Hi.

Is there anything I need to do to prevent this error from occurring?
Happens to me every day since update 41.

Thank you.





Code:
user:/AddOns/LibAsync/LibAsync.lua:49: user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryProcessingRequest.lua:126: no events processed and not at the end - something went wrong
stack traceback:
[C]: in function 'error'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryProcessingRequest.lua:126: in function 'GuildHistoryProcessingRequest:EnsureIterationIsComplete'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryProcessingRequest.lua:67: in function '(anonymous)'
(tail call): ?
[C]: in function 'pcall'
user:/AddOns/LibAsync/LibAsync.lua:29: in function 'DoCallback'
user:/AddOns/LibAsync/LibAsync.lua:63: in function 'DoJob'
user:/AddOns/LibAsync/LibAsync.lua:141: in function 'async.Scheduler'
stack traceback:
[C]: in function 'error'
user:/AddOns/LibAsync/LibAsync.lua:49: in function 'DoCallback'
user:/AddOns/LibAsync/LibAsync.lua:63: in function 'DoJob'
user:/AddOns/LibAsync/LibAsync.lua:141: in function 'async.Scheduler'
Report comment to moderator  
Reply With Quote
Unread 04/08/24, 07:02 AM  
Jysoul

Forum posts: 5
File comments: 25
Uploads: 0
After the update v9.3.7 and while doing guild history sync with LibHistoire, received the following error. Also running latest addon updates (using Minion).

user:/AddOns/LibAsync/LibAsync.lua:49: assert: Received event with invalid timestamp
stack traceback:
[C]: in function 'assert'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:535: in function 'func'
|caaaaaa<Locals> i = 452, event = [table:1]{eventIndex = 35103}, eventId = 93766707, eventTime = 1710234877 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:305: in function '(anonymous)'
(tail call): ?
[C]: in function 'pcall'
user:/AddOns/LibAsync/LibAsync.lua:29: in function 'DoCallback'
|caaaaaa<Locals> job = [table:2]{name = "LibHistoire162", lastCallIndex = 2}, callstackIndex = 2 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:63: in function 'DoJob'
|caaaaaa<Locals> job = [table:2], index = 2 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:141: in function 'async.Scheduler'
|caaaaaa<Locals> name = "LibHistoire162", runTime = 1524.2560022, GetGameTimeSeconds = [C]:-1, start = 1524.2496337891, now = 1524.2560022, allOnlyOnce = F </Locals>|r
stack traceback:
[C]: in function 'error'
user:/AddOns/LibAsync/LibAsync.lua:49: in function 'DoCallback'
|caaaaaa<Locals> job = [table:1]{name = "LibHistoire162", Error = "assert: Received event with in...", lastCallIndex = 1}, callstackIndex = 2, success = F, shouldContinue = "assert: Received event with in..." </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:63: in function 'DoJob'
|caaaaaa<Locals> job = [table:1], index = 2 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:141: in function 'async.Scheduler'
|caaaaaa<Locals> name = "LibHistoire162", runTime = 1524.2560022, GetGameTimeSeconds = [C]:-1, start = 1524.2496337891, now = 1524.2560022, allOnlyOnce = F </Locals>|r
Last edited by Jysoul : 04/08/24 at 07:03 AM.
Report comment to moderator  
Reply With Quote
Unread 04/13/24, 09:33 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 578
File comments: 1678
Uploads: 40
Originally Posted by Jysoul
After the update v9.3.7 and while doing guild history sync with LibHistoire, received the following error. Also running latest addon updates (using Minion).

user:/AddOns/LibAsync/LibAsync.lua:49: assert: Received event with invalid timestamp
stack traceback:
[C]: in function 'assert'
user:/AddOns/LibHistoire/guildHistoryCache/GuildHistoryCacheCategory.lua:535: in function 'func'
|caaaaaa<Locals> i = 452, event = [table:1]{eventIndex = 35103}, eventId = 93766707, eventTime = 1710234877 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:305: in function '(anonymous)'
(tail call): ?
[C]: in function 'pcall'
user:/AddOns/LibAsync/LibAsync.lua:29: in function 'DoCallback'
|caaaaaa<Locals> job = [table:2]{name = "LibHistoire162", lastCallIndex = 2}, callstackIndex = 2 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:63: in function 'DoJob'
|caaaaaa<Locals> job = [table:2], index = 2 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:141: in function 'async.Scheduler'
|caaaaaa<Locals> name = "LibHistoire162", runTime = 1524.2560022, GetGameTimeSeconds = [C]:-1, start = 1524.2496337891, now = 1524.2560022, allOnlyOnce = F </Locals>|r
stack traceback:
[C]: in function 'error'
user:/AddOns/LibAsync/LibAsync.lua:49: in function 'DoCallback'
|caaaaaa<Locals> job = [table:1]{name = "LibHistoire162", Error = "assert: Received event with in...", lastCallIndex = 1}, callstackIndex = 2, success = F, shouldContinue = "assert: Received event with in..." </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:63: in function 'DoJob'
|caaaaaa<Locals> job = [table:1], index = 2 </Locals>|r
user:/AddOns/LibAsync/LibAsync.lua:141: in function 'async.Scheduler'
|caaaaaa<Locals> name = "LibHistoire162", runTime = 1524.2560022, GetGameTimeSeconds = [C]:-1, start = 1524.2496337891, now = 1524.2560022, allOnlyOnce = F </Locals>|r
The error happens in LibHistoire. All I can say is, that ZOS renamed an instance handling guild history to streamline name convention.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: