-
-
Save rightfold/08633cccef0a763d39ce to your computer and use it in GitHub Desktop.
This file contains 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
fn sleep(timeout) { | |
return new Promise(fn(resolve) { | |
setTimeout(fn() { resolve(); }, timeout); | |
}); | |
} | |
async fn greetAfter(name, timeout) { | |
await sleep(timeout); // suspends until promise returned by sleep is resolved | |
return greet(name); | |
} | |
async fn main() { | |
val message = await greetAfter('Suzy', 2000); // suspends until promise returned by greetAfter is resolved | |
console.log(message); | |
} | |
main(); // this returns immediately |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment