Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close
NAME
    Wait - A missing shortcuts in JavaScript language.

SYNOPSIS
      JSAN.use('Wait');

      wait(
         // Wait for this function to return true
         function() {
             return (v1 == 100);
         },
         // ... and then do this
         function() {
             v2 = true;
         },
         // ... unless the waiting is so long
         function() {
             v3 = false;
         },
         // ... as 10000 ms.
         10000
      );

DESCRIPTION
    This library exports a function called 'wait'. It aims to simplify the
    standard setInterval-clearInterval pattern which is used to ensure the
    synchronous of data.

    One basic problem programming in javascript is about asynchrounous,
    especially when you're dealing with cross browser issue. Sometimes the
    returned object of "document.createElement('div')" may not have it's
    ".style" property ready when you want to use it.

    So here's what 'wait' does: It keeps checking whether a given etst
    passed or not periodically. Once the test passed, call the callabck. If
    the waiting time is too long, longer then the maximum, another failure
    callback is called.

    The 'wait' function can be used in two form: either with 3 arguments or
    4 arguments. The semantic of its 3-argument form is:

      wait(test, callback, max_wait)

    And for its 4-argument form, it would be:

      wait(test, callback, failure_callback, max_wait)

    It handles "setInterval()" and calls "clearInterval()" once the test
    passed, or elapsed over max waiting time. You may omit the last
    "max_wait" argument, in such case it never ends waiting, which means the
    "failure_callback" would never be called even if it's given. So you
    might just use this form for convienence:

      wait(test, callback)

    Waiting indefinitely might not be the best behaviour, but long as you
    can ensure that the test would be passing, it's golden.

AUTHOR
    Kang-min Liu <gugod@gugod.org>.

COPYRIGHT
    Copyright 2006, 2007, 2008, 2009 by Kang-min Liu <gugod@gugod.org>.

    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

    See <http://www.perl.com/perl/misc/Artistic.html>

Recent activity

Nothing to see here, move along.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.