How to make horseman chain synchronous?
See original GitHub issueI am doing something like the code below, where I have wrapped a horseman operation in a function that I want to return a value. The problem is, the chain gets started asynchronously so the function returns undefined immediately. Later on when horseman finishes, it console logs the correct value.
How can I cause the chain to block or return the value I want from the .then() / .evaluate() section?
var Horseman = require('node-horseman');
var horseman = new Horseman();
console.log("outside val: " + request("a"));
function request(query) {
horseman
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
.open('http://example.com/'+query)
.evaluate(function() {
return $('input[name="fieldName"]').val();
})
.then(function(value) {
console.log("Running then");
horseman.close();
if (value !== undefined) {
console.log("inside val: " + value);
return value;
}
});
}
Output:
outside val: undefined
Running then
inside val: correctValue
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to Loop Horseman instance while passing a variable in ...
I don't know this Horseman API but because it uses .then() function I assume it's a Promise. try to do this,
Read more >Nail Your Showmanship Pivot - Horse Illustrated
To win the class, Walquist says you need both horse and rider in sync and ... Bruce Walquist recommends threading your chain through...
Read more >Where Your Energy Meets Your Horse's Energy
Get the latest Eclectic Horseman magazine with exclusive horse training lessons, videos, and photos from Eclectic Horseman.
Read more >Ray Hunt, Horseman - THERE IS NO SUCH THING AS A ...
Good I've had a few racebred quarter horses I would have liked to see someone observe kingship to Shit go ahead I will...
Read more >Another Horseman - HealthHIV
If we don't get the food that we need to reach the people in need, whether it's in ... Current supply chain and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I got it thanks, I just had to rethink how my algorithm worked. I originally intended for it to branch out recursively (I’m a little used to that model as we do it that way for almost all recursive things in my classes)
Instead I made a queue and used the single recursive-like method in links.js. It works just about as fast as I need it to.
[Command Line Program] utilizing synchronous execution to grab the user input first then run the search using those values using horseman (https://gist.github.com/softe1988/7dab60e5cbfdd5f860fa59d1ddb44cd9)