【发布时间】:2022-11-20 03:57:14
【问题描述】:
我想做这个简单的逻辑:
- 我有返回值的可观察对象
- 我想使用该值并依次运行另外两个可观察对象
- 我想在两个连续完成后基于我的第一个可观察值返回值
这是我尝试用 cmets 解决我的问题
updateAvatar( @Headers() headers: { authorization: string }, @CurrentUserId() currentUserId: string, @UploadedFile() avatarFile: Express.Multer.File, ): Observable<{ avatarUrl: string }> { const obs1 = this.queue.send( PostCommands.uploadImage, new UploadImageCommandRequst( currentUserId, avatarFile.originalname, 'avatars', true, ), ); // returns observable const obs2 = obs1.pipe( map(({ imageUploadUrl, imageUrl }) => { // need await here this.httpService.put(imageUploadUrl, avatarFile.buffer); // returns observable // also need await here. patch must be executed after put this.httpService.patch( `${this.config.GATEWAY_URL}/user/profile`, { avatarUrl: imageUrl, }, { headers: { authorization: headers.authorization } }, ); // returns observable // value must be returned after patch executed return { avatarUrl: imageUrl, }; }), ); return obs2; }
【问题讨论】:
标签: rxjs