Skip to content

Instantly share code, notes, and snippets.

@fforres
Last active February 8, 2017 18:05
Show Gist options
  • Select an option

  • Save fforres/63c8291966c4733775473643751924ac to your computer and use it in GitHub Desktop.

Select an option

Save fforres/63c8291966c4733775473643751924ac to your computer and use it in GitHub Desktop.
test async
//FUNCION ASUYNCRONA; NO PREOCUPARSE DE ESTO;
var count = 0;
var asyncFunction = () => new Promise((res, rej) => {
setTimeout(() => {
if(count < 10) {
count = count+1;
console.log('Returning false');
res(false);
} else {
console.log('Returning true');
res(true);
}
}, 500)
})
//YHIS
async function waiter() {
var t = true
while(t) {
var a = await Promise.resolve(asyncFunction())
if(a !== false) {
t = false;
}
}
}
async function waiter2() {
let code = '';
do {
code = Math.random();
console.log('current code: ', code);
} while (!await Promise.resolve(asyncFunction()))
console.log('Final code is:', code);
}
// waiter()
waiter2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment