Created
May 29, 2019 11:29
-
-
Save VanTigranyan/242c49c090e05bc6a6e3f35baa4ce257 to your computer and use it in GitHub Desktop.
nested observables in loops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public getKernelAttachments(kernelId: IDBId) { | |
| this.waitingForFiles = kernelId; | |
| this.service.getKernelAttachments(kernelId) | |
| .pipe( | |
| mergeMap((fileIds: IDBId[]) => { | |
| const packsArray = fileIds.map((id) => { | |
| return this.service.getKernelFilePack(id); | |
| }); | |
| return forkJoin(...packsArray).pipe( | |
| map((packs) => { | |
| return packs; | |
| }), | |
| catchError((e) => { | |
| return of(e); | |
| }), | |
| ); | |
| })) | |
| .subscribe((packs) => { | |
| packs.map((pack) => { | |
| this.http.get(pack.url, {responseType: 'blob'}) | |
| .subscribe( | |
| (f) => { | |
| saveAs(f, pack.name); | |
| this.notify.create( | |
| 'The file has saved successfully!', | |
| 'Your file downloaded successfully and is ready for using!', | |
| 'success', | |
| ); | |
| this.waitingForFiles = null; | |
| }, | |
| (e: HttpErrorResponse) => { | |
| this.notify.create( | |
| 'Something went wrong!', | |
| `Downloading has failed!<br> Status Code: ${e.status} <br> Message: ${e.statusText}`, | |
| 'error', | |
| ); | |
| this.waitingForFiles = null; | |
| }, | |
| ); | |
| }); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment