Quantcast
Is there any way to throttle an arbitrary function? - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
09-13-19, 04:38 AM   #1
Odjur
A Murloc Raider
Join Date: Feb 2014
Posts: 6
Is there any way to throttle an arbitrary function?

I am currently writing my functions to run for N iterations before calling them again, but it would be much more convenient and consistent to be able to pass my functions off to a handler/scheduler and have them take care of them for me. This is an example of what I am trying to do:

Code:
local thread
local delay
local count = 0

local queue = function()
	for a = 1, 10000000 do
		count = a
	end
end

C_Timer.NewTicker(0, function()
	if queue then
		if not thread then
			thread = coroutine.create(function()
				delay = C_Timer.NewTicker(0, function()
					print(count)
					
					if coroutine.status(thread) == "dead" then
						queue = nil
						thread = nil
						delay:Cancel()
					else
						coroutine.yield()
					end
				end)
				
				queue()
			end)
		end
		
		coroutine.resume(thread)
	end
end)
I was trying to pass my functions to the variable 'queue' and have them turned into coroutines that would be yielded every frame. However it seems that C_Timer.NewTicker doesn't run asynchronously, so it never gets to yield the coroutine.

Is there any way to do what I am trying to do? It seems strange to me that I can't come up with a clean way to throttle my functions. Thanks for your help.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Is there any way to throttle an arbitrary function?

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