Quantcast Terminate callLater - ESOUI
Thread Tools Display Modes
03/02/20, 03:25 AM   #1
ExoY
 
ExoY's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 10
Terminate callLater

Hello,

i was wondering if there is a way to terminate the zo_callLater function, before it executes?

Here a minimalistic example of what i mean.

Lua Code:
  1. function foo.EnterCombat()
  2.   zo_callLater(function() d("you take too long") end, 5000)
  3. end
  4.  
  5. function foo.LeaveCombat()
  6.   -- terminate the zo_callLater
  7. end

Besides the option to terminate the callLater i would also need a way to identify the specifiy callLater, maybe by some form of id or such.

Is it even possible to implement something like this with the currently availiable tools?


(I am aware that in certain situations a workaround can be achieved with "RegisterForUpdate" and "UnregisterForUpdate")

Thanks in advance
  Reply With Quote
03/02/20, 03:44 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,343
You can! All you need to do is call UnregisterForUpdate for the name the callLater is registered with. It will return an id when you call it, so you can unregister it like this:

Lua Code:
  1. local function ClearCallLater(id)
  2.     EVENT_MANAGER:UnregisterForUpdate("CallLaterFunction"..id)
  3. end
  4.  
  5. function foo.EnterCombat()
  6.   foo.myHandle = zo_callLater(function() d("you take too long") end, 5000)
  7. end
  8.      
  9. function foo.LeaveCombat()
  10.   ClearCallLater(foo.myHandle)
  11. end
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
03/02/20, 04:33 AM   #3
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,709
Background information:

zo_callLater is nothing else than an
EVENT_MANAGER:RegisterForUpdate
with a pre-defined identifier prefix "CallLaterFunction" and an attached suffix which is not pre-defined.

https://github.com/esoui/esoui/blob/...alapi.lua#L197

And either zo_callLater or EVENET_MANAGER:RegisterForUpdate both return the unique ID of the registered handler so you can use this one to unregister it again via EVENT_MANAGER:UnregisterForUpdate
  Reply With Quote
03/02/20, 05:58 AM   #4
ExoY
 
ExoY's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 10
Thank you both for the quick and precise answers.

It was exactly what i was locking for and now i also now what zo_callLater really does.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Terminate callLater

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off