Periodicalexecuter
Upcoming SlideShare
Loading in...5
×
 

Periodicalexecuter

on

  • 1,206 views

Prototype Javascript

Prototype Javascript

Statistics

Views

Total Views
1,206
Views on SlideShare
1,206
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Periodicalexecuter Periodicalexecuter Presentation Transcript

  • Module PeriodicalExecuter
  • PeriodicalExecuter
    • This is a simple facility for periodical execution of a function.
    • This essentially encapsulates the native clearInterval/setInterval mechanism found in native Window objects
    • The only notable advantage provided by PeriodicalExecuter is that it shields you against multiple parallel executions of the callback function
    • This is especially useful if you use one to interact with the user at given intervals (e.g. use a prompt or confirm call):
    • This will avoid multiple message boxes all waiting to be actioned.
  • Creating a PeriodicalExecuter
    • The constructor takes two arguments the callback function, and the interval (in seconds ) between executions.
    • Once launched, a PeriodicalExecuter triggers indefinitely, until the page unloads or the executer is manually stopped
    • Example;
    • // Campfire style :-)
    •    new PeriodicalExecuter(pollChatRoom,  3 );
    •    new PeriodicalExecuter( function (pe) {
    •      if  (!confirm( 'Want me to annoy you again later?' ))
    •        pe.stop();  },  5 );
    •    // Note that there won't be a stack of such messages if the user takes  too long answering to the question...
    •  
    •  
    •  
  • Stop a PeriodicalExecuter
    • stop()
    • Stops the periodical executer (there will be no further triggers).
    • Once a PeriodicalExecuter is created, it constitues an infinite loop, triggering at the given interval until the page unloads.
    • Example;
    • var gCallCount =  0 ;
    • new PeriodicalExecuter( function (pe) {
    •    if  (++gCallCount >  3 )
    •      pe.stop();
    •    else
    •      alert(gCallCount);} ,  1 );
    • // Will only alert 1, 2 and 3, then the PE stops.
    •