fix(data-source): 兼容Promise.allSettled

This commit is contained in:
roymondchen 2024-06-13 17:03:48 +08:00
parent 5873842260
commit 7ee7f53938

View File

@ -74,6 +74,8 @@ class DataSourceManager extends EventEmitter {
});
const dataSourceList = Array.from(this.dataSourceMap);
if (typeof Promise.allSettled === 'function') {
Promise.allSettled<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds))).then((values) => {
const data: DataSourceManagerData = {};
const errors: Record<string, Error> = {};
@ -89,6 +91,15 @@ class DataSourceManager extends EventEmitter {
this.emit('init', data, errors);
});
} else {
Promise.all<Record<string, any>>(dataSourceList.map(([, ds]) => this.init(ds)))
.then(() => {
this.emit('init', this.data);
})
.catch(() => {
this.emit('init', this.data);
});
}
}
public async init(ds: DataSource) {