/**
* Wait until condition become 'false' and run function.
*
* @param {Function} condition - function that should return needed condition
* @param {Number} waitMs - timeout between re-check
* @param {Function} func - called when condition isn't 'false'
* @param {Object} [context] - context passed to main function
* @param {Array} [args] - arguments passed to main function
*/
function waitAndRun(condition, waitMs, func, context, args) {
if (condition.call(null, null)) {
setTimeout(function () {
waitAndRun(condition, waitMs, func);
}, waitMs);
return;
}
func.apply(context, args);
}