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
const assert = require('assert'); | |
test('Testing async code', async () => { | |
const first = await getAsyncResult(); | |
assert.strictEqual(first, 'foo'); | |
const second = await getAsyncResult2(); | |
assert.strictEqual(second, 'bar'); | |
}); |
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
return getAsyncResult() // A |
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
/** | |
* Always waits one second, then "toss a coin", having | |
* a 50/50 chance to get either true or false. Throws | |
* an error if false. | |
*/ | |
async function waitAndMaybeReject() { | |
await new Promise(r => setTimeout(r, 1000)); | |
const isHeads = Boolean(Math.round(Math.random())); |
OlderNewer