[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:
Andrey Lushnikov 2017-07-31 01:38:22 -07:00
parent 75a8d7b0c3
commit 73a99c6e0d

View File

@ -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;