ES6 异步操作和Async函数(12)_汽车市场报
广告位API接口通信错误,查看德得广告获取帮助

汽车市场报移动版

汽车市场报 > 汽车百科 >

ES6 异步操作和Async函数(12)

co TJ Holowaychuk20136Generator Generator var gen = function * () { var f1 = yield readFile( /etc/fstab ); var f2 = yield readFile( /etc/shells ); console .log(f1.toString()); console .log(f2.toString());}; coGenerator var co = require ( co );co(gen); Generatorco coPromisethen co(gen).then( function () { console .log( Generator );}); Generator co coGenerator Generator 1Thunk 2Promise Promisethen coThunkPromisecoGeneratoryieldThunkPromise ThunkPromiseco Promise fsreadFilePromise var fs = require ( fs ); var readFile = function ( fileName ) { return new Promise ( function ( resolve, done: false } console .log( await asyncIterator.next()); // { value: b, data ) { if (error) reject(error);resolve(data);}); });}; var gen = function * () { var f1 = yield readFile( /etc/fstab ); var f2 = yield readFile( /etc/shells ); console .log(f1.toString()); console .log(f2.toString());}; async var asyncReadFile = async function () { var f1 = await readFile( /etc/fstab ); var f2 = await readFile( /etc/shells ); console .log(f1.toString()); console .log(f2.toString());}; (责任编辑:admin)
广告位API接口通信错误,查看德得广告获取帮助