With Ecma Script 2017 You can use async-await and while together to do that And while will not crash or lock the program even variable never be true
//First define some delay function which is called from async function_x000D_
function __delay__(timer) {_x000D_
return new Promise(resolve => {_x000D_
timer = timer || 2000;_x000D_
setTimeout(function () {_x000D_
resolve();_x000D_
}, timer);_x000D_
});_x000D_
};_x000D_
_x000D_
//Then Declare Some Variable Global or In Scope_x000D_
//Depends on you_x000D_
let Variable = false;_x000D_
_x000D_
//And define what ever you want with async fuction_x000D_
async function some() {_x000D_
while (!Variable)_x000D_
await __delay__(1000);_x000D_
_x000D_
//...code here because when Variable = true this function will_x000D_
};_x000D_
////////////////////////////////////////////////////////////_x000D_
//In Your Case_x000D_
//1.Define Global Variable For Check Statement_x000D_
//2.Convert function to async like below_x000D_
_x000D_
var isContinue = false;_x000D_
setTimeout(async function () {_x000D_
//STOPT THE FUNCTION UNTIL CONDITION IS CORRECT_x000D_
while (!isContinue)_x000D_
await __delay__(1000);_x000D_
_x000D_
//WHEN CONDITION IS CORRECT THEN TRIGGER WILL CLICKED_x000D_
$('a.play').trigger("click");_x000D_
}, 1);_x000D_
/////////////////////////////////////////////////////////////
_x000D_
Also you don't have to use setTimeout in this case just make ready function asynchronous...