Last active
February 8, 2017 18:05
-
-
Save fforres/63c8291966c4733775473643751924ac to your computer and use it in GitHub Desktop.
test async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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