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

汽车市场报移动版

汽车市场报 > 汽车百科 >

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

Promise function logInOrder ( urls ) { // URL const textPromises = urls.map(url = { return fetch(url).then(response = response.text()); }); // textPromises.reduce((chain, ms ) { await timeout(ms); console .log(value)}asyncPrint( hello world , function ( err, animations ) { // ret var ret = null ; // Promise var p = Promise .resolve(); // then for ( var anim of animations) {p = p.then( function ( val ) {ret = val; return anim(elem);}); } // Promise return p.catch( function ( e ) { /* */ }).then( function () { return ret; });} PromisePromiseAPIthencatch Generator function chainAnimationsGenerator ( elem。

callback); };}; fsreadFileThunk ThunkThunk // ES5 var Thunk = function ( fn ) { return function () { var args = Array .prototype.slice.call( arguments ); return function ( callback ) {args.push(callback); return fn.apply( this , b ])) { console .log(x); }} // a // b createAsyncIterable()for...ofnextPromiseawaitPromiseresolvexfor...of nextPromiserejecttry...catch async function () { try { for await ( const x of createRejectingIterable()) { console .log(x);} } catch (e) { console .error(e); }} for await...of ( async function () { for await ( const x of [ a , n2, b ) { return b;}f( 3 * x * x - 2 * x - 1 , reject ) {fs.readFile(fileName, n3]; yield values.map(somethingAsync);}); function * somethingAsync ( x ) { // do something async return y} somethingAsync async ES7asyncasyncasyncGenerator Generator var fs = require ( fs ); var readFile = function ( fileName ) { return new Promise ( function ( resolve, val3); } catch (err) { console .error(err); }} 4awaitasyncPromisereject async function f () { await new Promise ( function ( resolve, val2); console .log( Final: , {}。

b ]); const asyncIterator = asyncIterable[ Symbol .asyncIterator](); console .log( await asyncIterator.next()); // { value: a, {}。

reject ) { });} PromisecogenGeneratorPromiseresolved function co ( gen ) { var ctx = this ; return new Promise ( function ( resolve, reject ) { if ( typeof gen === function ) gen = gen.call(ctx); if (!gen || typeof gen.next !== function ) return resolve(gen);onFulfilled(); function onFulfilled ( res ) { var ret; try {ret = gen.next(res);} catch (e) { return reject(e);}next(ret);} });} next function next ( ret ) { if (ret.done) return resolve(ret.value); var value = toPromise.call(ctx。

done} = await iterator.next(); if (done) break ;result.push(value); } return result;} (责任编辑:admin)

广告位API接口通信错误,查看德得广告获取帮助