admin管理员组文章数量:1320771
what's the usage of evaluateAsync
and when we have to use this function and what's the benefit of using this function .
in the below we see a poor documentation for this :
var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.evaluateJavaScript example.
any body can show a example of usage of evaluateAsync
in phantomjs
what's the usage of evaluateAsync
and when we have to use this function and what's the benefit of using this function .
in the below we see a poor documentation for this :
var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.evaluateJavaScript example.
any body can show a example of usage of evaluateAsync
in phantomjs
1 Answer
Reset to default 10This function allows you to execute any JavaScript code like the evaluate
API function.
But it will evaluate your code asynchronous. It means:
- Current execution context will not be blocked.
- It will not return any result.
Let's say you want execute some long-running JavaScript code, but you don't interested in its result. If you will use evaluate
, your current execution context will be blocked.
The documentation for evaluateAsync
is a bit wrong. The correct signature for evaluateAsync
is:
evaluateAsync(function, ms, args)
, where:
- function - the function to evaluate
- ms - time to wait before execution
- args - function arguments
Example:
evaluateAsync(function() {
console.log('Hi! I\'m evaluateAsync call!');
}, 1000);
Using in the real world:
- You want to capture some asynchronous events.
- Unit testing! AFAIK, PhantomJS runners use
evaluateAsync
to run unit tests.
本文标签: javascripthow we can use evaluateAsync in phantomjsStack Overflow
版权声明:本文标题:javascript - how we can use evaluateAsync in phantomjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742090293a2420224.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论