Skip to content

Instantly share code, notes, and snippets.

@felixcarmona
Last active August 29, 2015 14:06
Show Gist options
  • Save felixcarmona/548b9c7fd333526e0289 to your computer and use it in GitHub Desktop.
Save felixcarmona/548b9c7fd333526e0289 to your computer and use it in GitHub Desktop.
performWhen
define([], function () {
return function (task_closure, condition_closure, timeout_function) {
var itself = function () {
timeout_function(function () {
if (condition_closure()) {
task_closure();
} else {
itself();
}
}, 100);
};
itself();
};
});
/*
Usage example:
performWhen(
function () {
console.log('execute some code here'); // this block code will be executed when the condition function is satisfied
},
function () {
return $('#some_element').is(":visible") == false; // this is the condition function
},
$timeout // the angular $timeout, or setTimeout, etc
);
*/
@felixcarmona
Copy link
Author

if you want to use it without requirejs, just remove the define([], function () {, and store the function where you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment