Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Delaying a while loop in a coroutine.
Started by Ryan Abrahams Aug 06 2019 06:08 PM

2 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Ryan Abrahams

[GLOBAL: userInfoPane.html]
Ryan Abrahams
  • Observer

  • 5 posts
  • Corona SDK

Hi All,

 

I am usually a C programmer, very new to lua, very new to corona, and for some reason I have been pulled onto a project in the very late stage to help them with some functionality (I was doing the server backend, but they need help with the front end now too), and I am trying to work out how I would do the following.

 

I need to create something like a background thread that runs across scenes that makes a http request every 2 minutes.

 

The main issue I am finding right now is trying to find a way of putting a delay in the loop that will work even if the application is suspended (or backgrounded by android/ios). From my understanding, timer.performWithDelay() does not operate when the application is backgrounded.

 

In C I would basically thread a function that makes the request, then waits for 2000ms, in a while loop. Being very new to lua, and corona, I have been dumped in the deep end. Hope someone has some advice for me.

 

 

Thanks in advance,

Ryan



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 934 posts
  • Corona SDK

As far as I've understood, Corona does not support having the app running in the background (or the app running while suspended).



[TOPIC: post.html]
#3

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,366 posts
  • Corona SDK

coroutines are sequential, not concurrent, so can't create the type of "background thread" you wish.  and suspended means suspended, including all lua execution, including coroutines.  you'd have to go at least as deep as java to create a separate thread.




[topic_controls]
[/topic_controls]