I have been trying to make this code work on nightmarejs
new Nightmare({
show: false
}).goto('http://www.example.com')
.inject('js', 'jquery-3.1.0.js')
.evaluate(() = > {
interval = setInterval(go, 2000);
function go() {
clearInterval(interval);
}
})
.catch(function (error) {
console.error('Search failed:', error);
});
Why would this code never exit?
UPDATE
If I use the .end() method like this:
new Nightmare({
show: false
}).goto('http://www.example.com')
.inject('js', 'jquery-3.1.0.js')
.evaluate(() = > {
interval = setInterval(go, 2000);
function go() {
if (condition)
clearInterval(interval);
}
})
.end() <-----
.catch(function (error) {
console.error('Search failed:', error);
});
Then the program exists without letting the evaluate function finish