Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (threading)
Viewing all articles
Browse latest Browse all 19

Android, During a long operation, setTimeout not firing.

$
0
0

I have a very long operation that is running in the background, and timers do not run their callback function once I start the long operation, even in what SHOULD be a separate javascript context (IE, another window object with a URL). Consider this code:

timer = setTimeout(function() { doTimer(); }, 1000);
function doTimer()
{
    Ti.API.info('timer!');
    clearTimeout(timer);
    timer = setTimeout(function() { doTimer(); }, 1000);
}
 
function longFunction(thisFunc)
{
    // the real implementation is working with a very large data file
    i=0;
    while(i<99999999999999999999)
    {
        i++;
    }
}
setTimeout(function() { longFunction() },5000);
As you might imagine, the app starts up fine, and it says 'timer!' in the debug console 4 or 5 times, and then starts the 'long function' after 5 seconds as I've asked it to. During the 'long function' (until it's done) there is NO 'timer!' in the console.

And yes, I've tried executing it in what Titanium is calling a different execution context, by opening a separate window and using Ti.App.addeventListener to trigger function calls that are specific to the 2nd execution context containing my long operation. Surprisingly it does EXACTLY the same thing.

Anybody have an idea on how to get my 'long function' to run without destroying the flow of my app?

Before you say 'why are you running a timer every second' I'll answer that: I'm playing an audio file and I need progress time played and time remaining in the file. Because I am playing a local file, the only way to do this is to create this timer :(

Platform Information: Titanium SDK 1.7.5, OS X Lion, Android 2.2


Viewing all articles
Browse latest Browse all 19

Latest Images

Trending Articles



Latest Images