Skip to content

Instantly share code, notes, and snippets.

@legraphista
Created November 8, 2017 12:57
Show Gist options
  • Save legraphista/87511f79e95aa2d5c963517966ab368f to your computer and use it in GitHub Desktop.
Save legraphista/87511f79e95aa2d5c963517966ab368f to your computer and use it in GitHub Desktop.
Erratic async/await behaviour
const Nightmare = require('nightmare'); // 2.10.0
let thatSpecialPlaceInMemory;
const makeNightmare = async () => {
const n = new Nightmare({ show: true });
await n.useragent('custom ua');
await n.goto('about:blank');
thatSpecialPlaceInMemory = n;
console.log('n exists? before return', !!n);
return n;
};
const x = async () => {
const n = await makeNightmare();
console.log('n exists? after return', !!n);
if (n !== thatSpecialPlaceInMemory) {
throw 'return function was incorrect'
}
await thatSpecialPlaceInMemory.end()
};
x()
.then(console.log)
.catch(e => {
console.error(e);
thatSpecialPlaceInMemory.end().then(_ => _);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment