最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how we can use evaluateAsync in phantomjs - Stack Overflow

programmeradmin6浏览0评论

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

Share Improve this question asked Mar 18, 2014 at 9:01 MOBMOB 8532 gold badges13 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

This 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.
发布评论

评论列表(0)

  1. 暂无评论