Generator example, maintain a queue of a plurality of successively performed ajax

Generator example, maintain a queue of a plurality of successively performed ajax

introduced earlier need ps <Script the src = "https://unpkg.com/axios/dist/axios.min.js"> </ Script> 
//
Generator example, maintain a queue of a plurality of successively performed ajax function ajax (URL) { axios.get (URL) .then (RES => userGen.next (res.data)) } function * Steps () { the console.log ( 'fetching may Users' ); const Users = the yield Ajax (' HTTPS: // api.github.com/users' ); the console.log (Users); the console.log ( 'fetching may firstUser' ); const firstUser = the yield Ajax ( `HTTPS: // api.github.com/users / $ {Users [ 0]} `.login); the console.log (firstUser); Console.log('fetching followers'); const followers = yield ajax(firstUser.followers_url); console.log(followers); } const userGen = steps(); userGen.next();

 

 

 

...

Guess you like

Origin www.cnblogs.com/jwzhang/p/12112726.html