mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
[doclint] do not use util.promisify
util.promisify is available since node 8. This patch re-implements the method so that it works in node 7.
This commit is contained in:
parent
75a8d7b0c3
commit
73a99c6e0d
@ -16,7 +16,7 @@
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const {promisify} = require('util');
|
||||
|
||||
const readFileAsync = promisify(fs.readFile);
|
||||
const readdirAsync = promisify(fs.readdir);
|
||||
const writeFileAsync = promisify(fs.writeFile);
|
||||
@ -128,4 +128,27 @@ class SourceFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function(?)} nodeFunction
|
||||
* @return {function(?):!Promise<?>}
|
||||
*/
|
||||
function promisify(nodeFunction) {
|
||||
/**
|
||||
* @param {!Array<?>} options
|
||||
* @return {!Promise<?>}
|
||||
*/
|
||||
return function(...options) {
|
||||
return new Promise(function(fulfill, reject) {
|
||||
options.push(callback);
|
||||
nodeFunction.call(null, ...options);
|
||||
function callback(err, result) {
|
||||
if (err)
|
||||
reject(err);
|
||||
else
|
||||
fulfill(result);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = SourceFactory;
|
||||
|
Loading…
Reference in New Issue
Block a user