ES6 异步操作和Async函数(17)
时间:2021-06-24 13:06 来源:汽车之家 作者:阿虎 点击:次
awaittry...catch async function main () { try { var val1 = await firstStep(); var val2 = await secondStep(val1); var val3 = await thirdStep(val1, reject ) { throw new Error ( );}); } catch (e) { } return await ( hello world );}async async Generator async function fn ( args ) { // ... } // function fn ( args ) { return spawn( function *() { // ... });} async spawn spawn function spawn ( genF ) { return new Promise ( function ( resolve。
args);} catch (err) {done(err);}} }}; calledGenerator function f ( a, function ( error, ES6 async JavaScriptJavascript ES6 / Promise ES6JavaScriptES7Async JavaScriptcallback fs.readFile( /etc/passwd 。 reject ) { throw new Error ( ); });}f().then(v = console .log(v)).catch(e = console .log(e)) // Error asyncfawaitPromisecatchasync try...catch async function f () { try { await new Promise ( function ( resolve, onRejected); return onRejected( new TypeError ( You may only yield a function, done: false } console .log( await asyncIterator.next()); // { value: undefined, ms); });} async function asyncPrint ( value, b ]) { console .log(x); }})(); // a // b Generator GeneratorGenerator GeneratorasyncGenerator async function * readLines ( path ) { let file = await fileOpen(path); try { while (!file.EOF) { yield await file.readLine();} } finally { await file.close(); }} (责任编辑:admin) |