#26 ✓resolved
Joe Gornick

Convert Timer interval to be milliseconds

Reported by Joe Gornick | 2009-03-12 17:27:47 UTC

Compared to every other timer in other languages, timer always accepts milliseconds and not seconds.

I say we convert the interval property to accept milliseconds.

Comments and changes to this ticket

  • John-David Dalton
  • Kit Goncharov

    Kit Goncharov 2009-07-04 23:23:16 UTC

    That, or change the constructor to accept an options hash instead of just two arguments:

    new Fuse.Timer({
        callback: function(){
            //...
        },
        timeout: 5000, //`timeout` seems more concise than `interval`...
        unit: 'millisecond'
    });
    

    The disadvantage to this is that it creates more overhead, and also requires a lot more abstraction in the actual Timer class (and then there's the additional issue of which units to support). Another alternative might be a multiple option (so, for seconds, set timeout to 5 and multiple to 1000), but that also seems slightly redundant and unnecessary.

    I think using seconds for the timeout unit seems more intuitive, but, if it's inconsistent with other languages, then it's probably a good idea to switch it to milliseconds after all. Just playing around with various ideas... :)

  • John-David Dalton

    John-David Dalton 2009-07-05 09:14:11 UTC

    Something else to think about is

    // ActionScript 3 Timer Class
    var myIndetifier:Timer = new Timer(delay, repeat-count);
    myIdentifier.addEventListener(TimerEvent.TIMER, timerListener);
    function timerListener (e:TimerEvent):void{
    //commands
    }
    myIdentifier.start();
    

    Maybe later with an object event system something like this may be doable.
    Also they use the word delay, others use countDown, and others still use time intervals

  • John-David Dalton

    John-David Dalton 2009-07-05 09:20:38 UTC

    I dig the multiple option adds very little to overhead and allows for some customizations like:

    // boom Prototype compat.
    Fuse.Timer.defaultOptions.multiple = 1000;
    

    also currently we use defaultOptions in Fuse.Ajax.Base.defaultOptions would just options seem fitting sense it is on the constructor ? (Fuse.Ajax.Base.options or Fuse.Timer.options

  • John-David Dalton

    John-David Dalton 2009-07-05 09:22:28 UTC

    • Assigned user changed from “Joe Gornick” to “Kit Goncharov”
  • Kit Goncharov

    Kit Goncharov 2009-07-08 12:33:23 UTC

    • Tag cleared.

    Sorry, I accidentally deleted my fork of Fuse on GitHub. I'll refork it and re-push the patch again... :(

    What do you think about extending the timer capabilities to exception handling? So the options hash will look something like this:

    new Fuse.Timer({
        onTimeout: function(){ ... },
        onException: function(exception){ ... },
        timeout: 15,
        multiple: 1000
    });
    
  • John-David Dalton

    John-David Dalton 2009-07-08 12:40:22 UTC

    Careful with that delete :D

    I dig the exception handling, its should be a new ticket item though.

  • Kit Goncharov

    Kit Goncharov 2009-07-08 13:11:43 UTC

    The commit URL containing the Timer updates is:

    https://github.com/kitsg/fusejs/commit/4d5c3634b69420dfad3f51271820...

    In that commit, I accidentally left an erroneous entry in timer_test.js, so this commit fixes that:

    https://github.com/kitsg/fusejs/commit/00be5a50c8c0d2ac267a07d038a0...

  • Kit Goncharov

    Kit Goncharov 2009-07-08 13:11:57 UTC

    • Tag set to “patched”
  • Kit Goncharov

    Kit Goncharov 2009-07-08 13:41:58 UTC

    @JDD: OK, #35 covers exception handling.

  • John-David Dalton

    John-David Dalton 2009-07-09 13:55:17 UTC

    Ok I have been milling over these changes.
    I would think that because of it being a timer that some arguments should not be optional

    Fuse.Timer(callback, interval, options);
    
    and options can hold the multiplier and onException properties
  • John-David Dalton

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

JavaScript frameworks share similar features and functionality such as DOM manipulation, event registration, and CSS selector engines. FuseJS attempts to incorporate the strengths of these frameworks into one stable, efficient, and optimized core JavaScript framework.

People watching this ticket

Tags

Pages