From 7ee7f53938c99a47631b5fe1835a13c4bed4c3ed Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 13 Jun 2024 17:03:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(data-source):=20=E5=85=BC=E5=AE=B9Promise.a?= =?UTF-8?q?llSettled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/data-source/src/DataSourceManager.ts | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/data-source/src/DataSourceManager.ts b/packages/data-source/src/DataSourceManager.ts index 0125d82dc..cfdca078f 100644 --- a/packages/data-source/src/DataSourceManager.ts +++ b/packages/data-source/src/DataSourceManager.ts @@ -74,21 +74,32 @@ class DataSourceManager extends EventEmitter { }); const dataSourceList = Array.from(this.dataSourceMap); - Promise.allSettled>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => { - const data: DataSourceManagerData = {}; - const errors: Record = {}; - - values.forEach((value, index) => { - const dsId = dataSourceList[index][0]; - if (value.status === 'fulfilled') { - data[dsId] = this.data[dsId]; - } else if (value.status === 'rejected') { - errors[dsId] = value.reason; - } - }); - this.emit('init', data, errors); - }); + if (typeof Promise.allSettled === 'function') { + Promise.allSettled>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => { + const data: DataSourceManagerData = {}; + const errors: Record = {}; + + values.forEach((value, index) => { + const dsId = dataSourceList[index][0]; + if (value.status === 'fulfilled') { + data[dsId] = this.data[dsId]; + } else if (value.status === 'rejected') { + errors[dsId] = value.reason; + } + }); + + this.emit('init', data, errors); + }); + } else { + Promise.all>(dataSourceList.map(([, ds]) => this.init(ds))) + .then(() => { + this.emit('init', this.data); + }) + .catch(() => { + this.emit('init', this.data); + }); + } } public async init(ds: DataSource) {