3
我这个代码测试phantom-node
:Phantom.js - 如何使用promise而不是回调?
var http = require('http');
http.createServer(function (req, res) {
res.write('<html><head></head><body>');
res.write('<p>Write your HTML content here</p>');
res.end('</body></html>');
}).listen(1337);
var phantomProxy = require('phantom-proxy');
phantomProxy.create({'debug': true}, function (proxy) {
proxy.page.open('http://localhost:1337', function (result) {
proxy.page.render('scratch.png', function (result) {
proxy.end(function() {
console.log('done');
});
}, 1000);
});
});
它的工作原理,但我想改变它的东西,如:
phantomProxy.create()
.then(something)=>{...}
.then(something)=>{...}
.then(something)=>{...}
.catch((err)=>{
console.log(err);
proxy.end();
}
,使其更易于阅读。任何建议?
您可能希望有看看“异步”模块,我记得内置在node.js中。它允许你做一些类似于你想要的东西。 –
可能有一个库可以为你做,但它很容易创建你自己的承诺并包装所有这些功能。你想使用像ES6承诺还是像蓝鸟这样的图书馆? – Spidy
我认为不是ES6。但我绝对想要最简单的事情开始。 – sooon