mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Use customizable max concurrent number
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user