packages/okam-core/src/wx/request.js
function doRequest(reqOpts) {
    reqOpts = Object.assign({}, reqOpts);
    if (currRequestNum >= requestMaxNum) {
        return new Promise((resolve, reject) => {
            waitingQueues.push({
                options: reqOpts,
                resolve,
                reject
            });
        });
    }

    currRequestNum++;

    let rawComplete = reqOpts.complete;
    reqOpts.complete = function (...args) {
        currRequestNum--;

        rawComplete && rawComplete(...args);

        if (!waitingQueues.length) {
            return;
        }

        let processReqInfo = waitingQueues.shift();
        doRequest(processReqInfo.options).then(
            res => processReqInfo.resolve(res),
            err => processReqInfo.reject(err)
        );
    };

    return rawRequest(reqOpts);
}
function doRequest(reqOpts) {
    reqOpts = Object.assign({}, reqOpts);
    if (currRequestNum >= requestMaxNum) {
        return new Promise((resolve, reject) => {
            waitingQueues.push({
                options: reqOpts,
                resolve,
                reject
            });
        });
    }

    currRequestNum++;

    let rawComplete = reqOpts.complete;
    reqOpts.complete = function (...args) {
        currRequestNum--;

        rawComplete && rawComplete(...args);

        if (!waitingQueues.length) {
            return;
        }

        let processReqInfo = waitingQueues.shift();
        doRequest(processReqInfo.options).then(
            res => processReqInfo.resolve(res),
            err => processReqInfo.reject(err)
        );
    };

    return rawRequest(reqOpts);
}
function doRequest ( reqOpts ) { reqOpts = Object . assign ( { } , reqOpts ) ; if ( currRequestNum >= requestMaxNum ) { return new Promise ( ( resolve , reject ) => { waitingQueues . push ( { options : reqOpts , resolve , reject } ) ; } ) ; } currRequestNum ++ ; let rawComplete = reqOpts . complete ; reqOpts . complete = function ( ... args ) { currRequestNum -- ; rawComplete && rawComplete ( ... args ) ; if ( ! waitingQueues . length ) { return ; } let processReqInfo = waitingQueues . shift ( ) ; doRequest ( processReqInfo . options ) . then ( res => processReqInfo . resolve ( res ) , err => processReqInfo . reject ( err ) ) ; } ; return rawRequest ( reqOpts ) ; }
Do request

@param {Object} reqOpts the request options
@return {Promise}
Do request