Skip to content

Instantly share code, notes, and snippets.

View patarkf's full-sized avatar

Patrick Ferreira patarkf

View GitHub Profile
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');
});
/**
* 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()));