Tobie, > Function.prototype.repeat = function(interval) { > var fn = this; > if (arguments.length > 1) { > // not testsed but you get the idea > fn = fn.curry.apply(fn, Array.prototype.slice.call(arguments, 1)); > } > return new PeriodicalExecuter(fn, interval); > > }
If sticking to the PE approach there's no internal self-stop mechanism (is there?), which i see as a nice touch in the above proposal (for what my opinion is worth). What about (from 1.6.1_rc2): onTimerEvent: function() { if (!this.currentlyExecuting) { try { this.currentlyExecuting = true; if (this.execute()===false) // MOD this.stop(); // NEW } catch(e) { /* empty catch for clients that don't support try/finally */ } finally { this.currentlyExecuting = false; } } } Just tossing in my 2 cents because i'm intrigued by that feature. -joe t. On Jun 26, 6:02 am, Tobie Langel <tobie.lan...@gmail.com> wrote: > > How to stop it? arguments? > > Stopping it is as easy as: > > pe = foo.repeat(); > pe.stop(); > > Passing arguments would require some simple currying: > > Function.prototype.repeat = function(interval) { > var fn = this; > if (arguments.length > 1) { > // not testsed but you get the idea > fn = fn.curry.apply(fn, Array.prototype.slice.call(arguments, 1)); > } > return new PeriodicalExecuter(fn, interval); > > } > > This may come to you twice, but this is slightly updated: > > >http://jsbin.com/opimu > > > This repeat() method def is 775Bytes, accepts arguments like delay/defer, > > uses setTimeout (returns initial setTimeout index) and has a stopping > > mechanism. > > What's the point in returning setTimeout index? That will set > expectations which can't be met: developers will expect to be able to > stop the functions calls by clearing it. > > Are you sure your proposal fixes all of the small issues PE fixes? For > example, does it guarantee that the function will continue being > called if it happens to once throw an error. Does it avoid calling the > function again if a previous function is still executing, etc.? > > I understand your eagerness to move away from a model you dislike, but > that shouldn't make you throw away all of the work that's been put > into previous solutions. > > FWIW, I just noticed a patch wasn't applied to PE in current trunk > (it's missing a throw statement). > > Best, > > Tobie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---