while (somecondition) { try { await sleep(1000); somecondition = await someAsyncAction(); } catch(err) { } }
function iff(condition, method) { return Promise.try(condition).then(result => { if (result) { return method(); } }); } function whilst(condition, method) { return iff(condition, () => { return Promise.try(method) .then(whilst.bind(null, condition, method)); }); } whilst(someAsyncAction, Promise.sleep.bind(null, 1000)) .catch(err => { // ... })