Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How to stop Core.asyncCall? — Gideros Forum

How to stop Core.asyncCall?

Apollo14Apollo14 Member
edited September 2019 in Code snippets
Hi guys!

Core.asyncCall is very handy for working with delays, personally I use it this way very frequently.
But sometimes we need to close scene/popup before Core.asyncCall stopped executing.
How to properly do it?
	local function scaleTextsAndBtn()
		local tempFontScale=1.02
 
		Core.yield(.2)
		txt1_noads:setScale(tempFontScale)
		Core.yield(.1)
		txt1_noads:setScale(1)
 
		txt2_plusincome:setScale(tempFontScale)
		Core.yield(.1)
		txt2_plusincome:setScale(1)
 
		txt3_instantgift:setScale(tempFontScale)
		Core.yield(.1)
		txt3_instantgift:setScale(1) 
 
		txt4_dailyreward:setScale(tempFontScale) --scene may need to be closed somewhere here, and if it's closed, function naturally crashes
		Core.yield(.1)
		txt4_dailyreward:setScale(1)
 
 
		Core.yield(.1)
		btn_OK:setScale(1.04)
		Core.yield(.2)
		btn_OK:setScale(1)
	end
 
	Core.asyncCall(scaleTextsAndBtn)
I guess it could be handy to have a command like 'Core.stopAsyncCall? (Or maybe not?)
> Newcomers roadmap: from where to start learning Gideros
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)

Comments

  • hgy29hgy29 Maintainer
    Accepted Answer
    In fact, no. It seemed dangerous to attempt to stop a lua coroutine in the middle of its work. I felt that it was better if the developer could handle interruption by himself in his code. Ex:
    local interrupted=false
    Core.asyncCall(function ()
     --Do stuff
     Core.yield(1) if interrupted then return end
     --More stuff
     Core.yield(1) if interrupted then return end
     -- Final stuff
    end)
     
    --Later
    interrupted=true --Make sure the async call will stop ASAP

    Likes: MoKaLux, antix

    +1 -1 (+2 / -0 )Share on Facebook
  • thx got it! will do it with triggers!

    Likes: MoKaLux

    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.