如果同时发送两个相同的获取请求,每个获取请求如何知道要消耗哪个响应?

时间:2018-09-05 15:58:33

标签: google-chrome fetch

如果同时发送两个相同的获取请求,每个获取请求如何知道要消耗哪个响应?

说我喜欢这样:

    var array = [
        {
          "title": "House Coffee",
          "weight": "1kg",
          "grind": "filter",
          "quantity": 5
        },
        {
          "title": "House Coffee",
          "weight": "1kg",
          "grind": "filter",
          "quantity": 5
        },
        {
          "title": "House Coffee",
          "weight": "250g",
          "grind": "Whole Beans",
          "quantity": 4
        },
        {
          "title": "House Coffee",
          "weight": "250g",
          "grind": "Whole Beans",
          "quantity": 2
        }
    ];

    var result = [];

    for (var i = 0; i < array.length; i++) {
        var a = array[i];
        var foundIndex = -1;

        for (var j = 0; j < result.length && foundIndex == -1; j++) {
            var b = result[j];

            if(a['title'] == b['title'] && a['grind'] == b['grind'] && a['weight'] == b['weight']){
                foundIndex = j;
            }
        }   

        if(foundIndex == -1){
            result.push(a);
        }else{
            result[foundIndex]['quantity'] += a.quantity;
        }
    }

第一个请求的响应最终如何被发送方消耗,而不是由另一个获取?

0 个答案:

没有答案