feat(data-source): timing改成串行

This commit is contained in:
roymondchen 2023-09-19 19:41:53 +08:00
parent 1c6c9ab3e8
commit 28b3d2e4b3
2 changed files with 12 additions and 8 deletions

View File

@ -94,11 +94,15 @@ class DataSourceManager extends EventEmitter {
} }
}); });
await Promise.all(beforeInit.map((method) => method({ params: {}, dataSource: ds, app: this.app }))); for (const method of beforeInit) {
await method({ params: {}, dataSource: ds, app: this.app });
}
await ds.init(); await ds.init();
await Promise.all(afterInit.map((method) => method({ params: {}, dataSource: ds, app: this.app }))); for (const method of afterInit) {
await method({ params: {}, dataSource: ds, app: this.app });
}
this.setData(ds); this.setData(ds);

View File

@ -119,18 +119,18 @@ export default class HttpDataSource extends DataSource {
public async request(options: HttpOptions) { public async request(options: HttpOptions) {
try { try {
await Promise.all( for (const method of this.beforeRequest) {
this.beforeRequest.map((method) => method({ options, params: {}, dataSource: this, app: this.app })), await method({ options, params: {}, dataSource: this, app: this.app });
); }
const res = await this.fetch?.({ const res = await this.fetch?.({
...this.httpOptions, ...this.httpOptions,
...options, ...options,
}); });
await Promise.all( for (const method of this.afterRequest) {
this.afterRequest.map((method) => method({ res, options, params: {}, dataSource: this, app: this.app })), await method({ res, options, params: {}, dataSource: this, app: this.app });
); }
if (this.schema.responseOptions?.dataPath) { if (this.schema.responseOptions?.dataPath) {
const data = getValueByKeyPath(this.schema.responseOptions.dataPath, res); const data = getValueByKeyPath(this.schema.responseOptions.dataPath, res);