Use customizable max concurrent number

This commit is contained in:
pandamicro
2017-05-26 18:28:47 +08:00
parent 65662e0dd2
commit 78428b4943
2 changed files with 12 additions and 3 deletions
+2 -3
View File
@@ -312,7 +312,6 @@ var Downloader = function (extMap) {
this.id = ID;
this.async = true;
this.pipeline = null;
this.maxConcurrent = cc.sys.isMobile ? 2 : 512;
this._curConcurrent = 0;
this._loadQueue = [];
@@ -332,13 +331,13 @@ Downloader.prototype.addHandlers = function (extMap) {
Downloader.prototype.handle = function (item, callback) {
var self = this;
var downloadFunc = this.extMap[item.type] || this.extMap['default'];
if (this._curConcurrent < this.maxConcurrent) {
if (this._curConcurrent < cc.macro.DOWNLOAD_MAX_CONCURRENT) {
this._curConcurrent++;
downloadFunc.call(this, item, function (err, result) {
// Concurrent logic
setTimeout(function () {
self._curConcurrent = Math.max(0, self._curConcurrent - 1);
while (self._curConcurrent < self.maxConcurrent) {
while (self._curConcurrent < cc.macro.DOWNLOAD_MAX_CONCURRENT) {
var nextOne = self._loadQueue.shift();
if (!nextOne) {
break;
+10
View File
@@ -1898,6 +1898,16 @@ cc.macro = {
* @default true
*/
ENABLE_TILEDMAP_CULLING: true,
/**
* !#en
* The max concurrent task number for the downloader
* !#zh
* 下载任务的最大并发数限制,在安卓平台部分机型或版本上可能需要限制在较低的水平
* @property {Number} DOWNLOAD_MAX_CONCURRENT
* @default 64
*/
DOWNLOAD_MAX_CONCURRENT: 64,
};
/**