Skip to content

Instantly share code, notes, and snippets.

@flyingzl
Created February 21, 2013 08:21
Show Gist options
  • Save flyingzl/5003154 to your computer and use it in GitHub Desktop.
Save flyingzl/5003154 to your computer and use it in GitHub Desktop.
var DeferredHelper = {
objectVariableIsSet: function(object, variableName) {
var dfd = $.Deferred();
var interval = setInterval(function() {
if (object[variableName] !== undefined) {
clearInterval(interval);
console.log('objectVariableIsSet');
dfd.resolve()
}
}, 10);
return dfd.promise();
},
arrayContainsElements: function(array) {
var dfd = $.Deferred();
var interval = setInterval(function() {
if (array.length > 0) {
clearInterval(interval);
console.log('arrayContainsElements');
dfd.resolve()
}
}, 10);
return dfd.promise();
}
}
var executeThis = function() {
console.log('ok!');
}
var object = {};
object.var = undefined;
var array = [];
$.when(DeferredHelper.arrayContainsElements(array)).then(executeThis);
$.when(DeferredHelper.objectVariableIsSet(object, 'var')).then(executeThis);
setTimeout(function() {
object.var = 2;
array.push(2);
array.push(3);
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment