[英]Interaction of VO, Generators, Promises and return object.
I'm trying to understand how nightmare and vo interact. 我想了解噩梦和vo如何相互作用。 Please find below the (almost) original example of the nightmare page.
请在(几乎)噩梦页面的原始示例下面找到。
Can anyone please give me a hint how to find out the sequence of things which happen, ie 任何人都可以给我一个提示,如何找出发生的事情的顺序,即
Unfortunately, nightmare documentation doesn't say how its design works (interaction with promises and generators). 不幸的是,噩梦文档没有说明其设计如何工作(与Promise和生成器的交互)。
If anybody can think of an example how to manually resolve the run() promise and trigger all of the .next() which are necessary to make the generator function work as intended, this would already be a big help. 如果有人想到一个示例,如何手动解决run()承诺并触发所有使生成器函数按预期工作所必需的.next(),那么这将是一个很大的帮助。
var Nightmare = require('nightmare');
var vo = require('vo');
vo( run() )(function(err, result) {
if (err) throw err;
console.log("end result length: ", result.length);
});
function *run() {
var x = Date.now();
var nightmare = Nightmare();
var html = yield nightmare
.goto('http://google.com')
.evaluate(function() {
return document.getElementsByTagName('html')[0].innerHTML;
});
console.log("done in " + (Date.now()-x) + "ms");
console.log("result:", html.length);
yield nightmare.end();
return html;
}
Thanks ! 谢谢 !
You need to pass the method in by name and not actually call it. 您需要按名称传递方法,而不实际调用它。 Vo will call the method when it runs.
Vo将在运行时调用该方法。 The code should read
该代码应阅读
vo( run )(function(err, result) {
if (err) throw err;
console.log("end result length: ", result.length);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.