Skip to content

Commit 7ee7f53

Browse files
author
roymondchen
committed
fix(data-source): 兼容Promise.allSettled
1 parent 5873842 commit 7ee7f53

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

packages/data-source/src/DataSourceManager.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,32 @@ class DataSourceManager extends EventEmitter {
7474
});
7575

7676
const dataSourceList = Array.from(this.dataSourceMap);
77-
Promise.allSettled<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => {
78-
const data: DataSourceManagerData = {};
79-
const errors: Record<string, Error> = {};
80-
81-
values.forEach((value, index) => {
82-
const dsId = dataSourceList[index][0];
83-
if (value.status === 'fulfilled') {
84-
data[dsId] = this.data[dsId];
85-
} else if (value.status === 'rejected') {
86-
errors[dsId] = value.reason;
87-
}
88-
});
8977

90-
this.emit('init', data, errors);
91-
});
78+
if (typeof Promise.allSettled === 'function') {
79+
Promise.allSettled<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => {
80+
const data: DataSourceManagerData = {};
81+
const errors: Record<string, Error> = {};
82+
83+
values.forEach((value, index) => {
84+
const dsId = dataSourceList[index][0];
85+
if (value.status === 'fulfilled') {
86+
data[dsId] = this.data[dsId];
87+
} else if (value.status === 'rejected') {
88+
errors[dsId] = value.reason;
89+
}
90+
});
91+
92+
this.emit('init', data, errors);
93+
});
94+
} else {
95+
Promise.all<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds)))
96+
.then(() => {
97+
this.emit('init', this.data);
98+
})
99+
.catch(() => {
100+
this.emit('init', this.data);
101+
});
102+
}
92103
}
93104

94105
public async init(ds: DataSource) {

0 commit comments

Comments
 (0)