Created
February 26, 2012 17:01
-
-
Save droot/1917722 to your computer and use it in GitHub Desktop.
Use of Async IF construct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* function to detect if a box of given color is visible on screen or not */ | |
is_box_visible = function(color) { | |
var selector; | |
selector = "." + color + "box:visible"; | |
return $(selector).length > 0; | |
}; | |
$.when(async_if(is_box_visible, 'green') /* green box is visible */, | |
async_if(is_box_visible, 'red') /* red box is visible */ | |
).then( | |
function() { | |
/* when both the red and green box appeared, inject a blue box */ | |
inject_box('blue'); | |
} | |
); | |
/* a timeout sample usecase, detect a redbox within 10seconds of start */ | |
async_if(is_box_visible, 'red', 10000).then( | |
function(color) { | |
alert('red box detected'); | |
}, | |
function(status) { | |
alert("couldn't detect redbox 10 seconds...."); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment