es6-promisify
使用样板回调函数将基于回调的函数转换为ES6 / ES2015 Promises。
安装
用安装
npm install es6-promisify
例子
const { promisify } = require ( "es6-promisify" ) ;
// Convert the stat function
const fs = require ( "fs" ) ;
const stat = promisify ( fs . stat ) ;
// Now usable as a promise!
try {
const stats = await stat ( "example.txt" ) ;
console . log ( "Got stats" , stats ) ;
} catch ( err ) {
console
1