Why can the nodecomodule be node co call interfaces in parallel?

  node.js, question

InnodeEnd call interface.
There is alistPages,forLoop inside calls the interface once every time to fetch information, which leads to frequent serial calls of the interface and takes a lot of time.
Switch tocoAfter the modules are called together, the speed is greatly increased. The question arises, whycoWill it become a parallel calling interface?

UsecoThe following is the general code: several functions inside are functions to call interfaces.

for (var i=0;  i<feedCount;  I plus)
 var item = {
 offerDetails: getOfferDetails(),
 feedPVCount: getFeedCount(),
 beSavedCount: getFavedCount()
 var defer = co(function* () {
 return yield item;
 results = yield results;

1. co () wraps the generator function as promise
2. results is a promise array that can be iterated; If the Promise array or the object with the property value of Promise object follows yield, these Promises are executed in parallel.

Specific you can look at the source code of co:

function toPromise(obj) {
 //Make sure obj is meaningful
 if (!  obj) return obj;
 //If it is already a Promise object, directly return obj
 if (isPromise(obj)) return obj;
 //If it is a generator function or a ready-made generator object, obj is directly passed into the co function as a parameter, and this co function
 //The returned "shell Promise" is used as the returned Promise.
 if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj);
 //If obj is a function, it is directly regarded as a function conforming to the thunk specification (what thunk function is will not be discussed here in detail.  .  ), direct conversion
 if ('function' == typeof obj) return thunkToPromise.call(this, obj);
 //If the Promise array, call the arrayToPromise method
 if (Array.isArray(obj)) return arrayToPromise.call(this, obj);
 //if the attribute value is the object of Promise object, call the objectToPromise method
 if (isObject(obj)) return objectToPromise.call(this, obj);
 return obj;
 function arrayToPromise(obj) {
 // Promise.all parallel execution
 return Promise.all(obj.map(toPromise, this));