Created
November 8, 2017 12:57
-
-
Save legraphista/87511f79e95aa2d5c963517966ab368f to your computer and use it in GitHub Desktop.
Erratic async/await behaviour
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 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