单例模式
ts
// 限制浏览器最大传输六条数据
export class LimitPromise {
constructor(max) {
// 异步任务的并发上限
this._max = max || 6
// 单例模式复用
this.instance = null
}
// 单例
static getInstance(max) {
if( !this.instance ) {
this.instance = new LimitPromise(max)
}
return this.instance
}
}