www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: sleep() pause() wait()

  1. #16
    Join Date
    Mar 2009
    Posts
    496
    Although the original question concerned how to pause the execution of the program, might I suggest a different approach to accomplish your objective. Assuming that your code works, except for delays, you might want to set the CSS on your hexagons (either visibility or display) so that they can't be seen when they're drawn. Draw them all, even though the user can't see them, and then use a procedure like I've shown you to make them visible at intervals. That way you wouldn't really have to modify your existing code to any great extent.

    Just a thought, and I'm glad if I was of some help to you.
    Last edited by Tcobb; 03-16-2014 at 08:53 AM.

  2. #17
    Join Date
    Feb 2006
    Location
    Buckingham, UK. (the Town, not the Palace)
    Posts
    148
    Hi Tcobb,
    Nice suggestion - but -
    I'm using JS to calculate the placing of the hexagons,
    AND to calculate and adjust the rgb(r,g,b) values.
    (not that I have anything against CSS !)

    But I take your point, I have both calculations in separate functions,
    I might be able to call them at intervals. I'll give that a go.
    Thanks,
    JJ

  3. #18
    Join Date
    Mar 2014
    Posts
    24

    function

    What is importance of these functions?.....................................

  4. #19
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,348
    My example is time based, yours is a number based, counting depends on processor speed which will be different for older machines than newer machines with faster processors.

    This:-
    Code:
    var n = new Date();
    var e = n.getTime() +1000;
    while( e >= new Date().getTime() );
    will make a time reference, add 1000 to it (1 second in milliseconds) then loop until the new time reference has passed by at lease 1000 milliseconds, note that it is not counting a value.

    It is not the same as
    Code:
    for(c=0; c<1000; c++);
    which will count 1000 iterations ans depending on the processor, could take a fraction of the time, eg a couple of milliseconds to more than a second for really old computers.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #20
    Join Date
    Mar 2009
    Posts
    496
    This:-
    Code:

    var n = new Date();
    var e = n.getTime() +1000;
    while( e >= new Date().getTime() );

    will make a time reference, add 1000 to it (1 second in milliseconds) then loop until the new time reference has passed by at lease 1000 milliseconds, note that it is not counting a value.
    And if you use this to create a "pause" and you set it for a sufficient period of time your browser will flash the user a "long running script" message. Set it for 20 minutes and see, although it should only take about 4 or 5 minutes. And it doesn't matter if a single pause isn't sufficient, what counts is how long the entire script takes to run.

    Secondly, if you have some other javascript functionality built into the page, such as clicking on an element to do whatever, you'll find that it really has problems working while your pause loop is running.

    A function that is executed as a result of setTimeout is different. It starts out with a brand new instance of the "browser timer" so you don't have this problem.

  6. #21
    Join Date
    Feb 2006
    Location
    Buckingham, UK. (the Town, not the Palace)
    Posts
    148
    Quote Originally Posted by simar View Post
    What is importance of these functions?.....................................
    Nothing serious.
    I was building a 'honeycomb' of 61 small hexagons.
    I wanted to view the build in slow motion.
    Thanks,
    JJ

  7. #22
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,348
    Quote Originally Posted by Tcobb View Post
    And if you use this to create a "pause" and you set it for a sufficient period of time your browser will flash the user a "long running script" message. Set it for 20 minutes and see, although it should only take about 4 or 5 minutes. And it doesn't matter if a single pause isn't sufficient, what counts is how long the entire script takes to run.

    Secondly, if you have some other javascript functionality built into the page, such as clicking on an element to do whatever, you'll find that it really has problems working while your pause loop is running.

    A function that is executed as a result of setTimeout is different. It starts out with a brand new instance of the "browser timer" so you don't have this problem.
    Why on earth would someone want to set a long pause?

    The OP requested a pause for a reason, whatever that was and if it is going to cause problems with interactivity for users, then that is the problem of the programmer to decide on if they stop using pauses.

    Only thing I can see a pause being used for is to either, pause an output to a display or to mimics the pause() / sleep() functions in a web browser emulator for another language.

    Unless the OP comes clean with the true purpose or need for this scripting, we can be talking cross purposes all day long.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #23
    Join Date
    Feb 2006
    Location
    Buckingham, UK. (the Town, not the Palace)
    Posts
    148

    still on sleep,pause wait

    Hi //./
    You say
    Unless the OP comes clean with the true purpose or need for this scripting, we can be talking cross purposes all day long.
    I didn't realise I was hiding anything. I said I was running some SVG under JS control. The JS runs the SVG so quickly the construction of the image is hidden.

    I'll go back and animate the SVG. Then I won't need to sleep, pause or wait.

    Thanks, everyone.
    JJ

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles