Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Convert Timer interval to be milliseconds

#26

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.

Reported by Joe Gornick · March 12th, 2009 @ 05:27 PM

State: resolved
Milestone: none
Assigned to: Kit Goncharov Kit Goncharov

Activity

  1. John-David Dalton
  2. Kit Goncharov
    Kit Goncharov

    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... :)

    July 4th, 2009 @ 11:23 PM

  3. John-David Dalton
    John-David Dalton

    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

    July 5th, 2009 @ 09:14 AM

  4. John-David Dalton
    John-David Dalton

    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

    July 5th, 2009 @ 09:20 AM

  5. John-David Dalton
    John-David Dalton
    • Assigned user changed from Joe Gornick to Kit Goncharov

    July 5th, 2009 @ 09:22 AM

  6. Kit Goncharov
    Kit Goncharov
    • 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
    });
    

    July 8th, 2009 @ 12:33 PM

  7. John-David Dalton
    John-David Dalton

    Careful with that delete :D

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

    July 8th, 2009 @ 12:40 PM

  8. Kit Goncharov
    Kit Goncharov

    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...

    July 8th, 2009 @ 01:11 PM

  9. Kit Goncharov
  10. Kit Goncharov
  11. John-David Dalton
    John-David Dalton

    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

    July 9th, 2009 @ 01:55 PM

  12. 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.