Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create Timer for neko/cpp when NME/OpenFL are not used #3

Open
fponticelli opened this issue Sep 24, 2014 · 1 comment
Open

create Timer for neko/cpp when NME/OpenFL are not used #3

fponticelli opened this issue Sep 24, 2014 · 1 comment

Comments

@fponticelli
Copy link
Owner

No description provided.

@fponticelli
Copy link
Owner Author

From Hugh on the ML:

I guess the first question is do you want sync or async timer callbacks? Sync is probably the most "cross platform" way.

I think the haxe timer class could easily be extended for non event driver apps by having a function "processTimers()". So like this:

public static function main() {
   var count = 10;
   Timer.delay(function() trace("Hi"), 1000 );
   Timer.processTimers();
}

And a sync processTimers can be created without any threads, by creating a list of pending timers.

public static function processTimers() {
   while(true) {
       var nextTimer = findNextTimer();  // Get one with least due time
       if (nextTimer==null)
          break;
       var delay = nextTimer.due - stamp();
       if (delay>0)
          sleep(delay);
       nextTimer.run();
   }
}

Whether you want to automagically call processTimers() via macro or otherwise is a minor matter, but explicit calling is not that hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant