diff --git a/utils/doclint/SourceFactory.js b/utils/doclint/SourceFactory.js index 0aaa6ce0c87..c1b0b2d1a35 100644 --- a/utils/doclint/SourceFactory.js +++ b/utils/doclint/SourceFactory.js @@ -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;