Mercurial > hg > ugly-duckling
comparison src/app/services/feature-extraction/feature-extraction.service.ts @ 324:e433a2da0ada
Refactor the import library logic slightly to waterfall the loading of the libraries and list requests, and send one response when all libraries have been loaded.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Tue, 16 May 2017 16:16:57 +0100 |
parents | 98490d0ceb77 |
children | e401995304a7 |
comparison
equal
deleted
inserted
replaced
323:72673c954216 | 324:e433a2da0ada |
---|---|
6 SimpleRequest, | 6 SimpleRequest, |
7 SimpleResponse | 7 SimpleResponse |
8 } from 'piper/HigherLevelUtilities'; | 8 } from 'piper/HigherLevelUtilities'; |
9 import {Subject} from 'rxjs/Subject'; | 9 import {Subject} from 'rxjs/Subject'; |
10 import {Observable} from 'rxjs/Observable'; | 10 import {Observable} from 'rxjs/Observable'; |
11 import {Http, Response} from '@angular/http'; | 11 import {Http} from '@angular/http'; |
12 import { | 12 import { |
13 countingIdProvider, | 13 countingIdProvider, |
14 WebWorkerStreamingClient | 14 WebWorkerStreamingClient |
15 } from 'piper/client-stubs/WebWorkerStreamingClient'; | 15 } from 'piper/client-stubs/WebWorkerStreamingClient'; |
16 import {RequestId} from 'piper/protocols/WebWorkerProtocol'; | 16 import {RequestId} from 'piper/protocols/WebWorkerProtocol'; |
61 countingIdProvider(0) | 61 countingIdProvider(0) |
62 ); | 62 ); |
63 } | 63 } |
64 | 64 |
65 list(): Promise<ListResponse> { | 65 list(): Promise<ListResponse> { |
66 return this.client.list({}); | 66 return this.client.list({}).then(response => { |
67 this.librariesUpdated.next(response); | |
68 return response; | |
69 }); | |
67 } | 70 } |
68 | 71 |
69 extract(analysisItemId: string, request: SimpleRequest): Promise<void> { | 72 extract(analysisItemId: string, request: SimpleRequest): Promise<void> { |
70 let config: StreamingConfiguration; | 73 let config: StreamingConfiguration; |
71 return collect(this.client.process(request), val => { | 74 return collect(this.client.process(request), val => { |
85 outputDescriptor: config.outputDescriptor | 88 outputDescriptor: config.outputDescriptor |
86 }); | 89 }); |
87 }); | 90 }); |
88 } | 91 } |
89 | 92 |
90 updateAvailableLibraries(): Observable<AvailableLibraries> { | 93 updateAvailableLibraries(): void { |
91 return this.http.get(this.repositoryUri) | 94 this.http.get(this.repositoryUri) |
92 .map(res => { | 95 .toPromise() // just turn into a promise for now to subscribe / execute |
93 const map = res.json(); | 96 .then(res => { |
94 this.worker.postMessage({ | 97 this.worker.postMessage({ |
95 method: 'addRemoteLibraries', | 98 method: 'addRemoteLibraries', |
96 params: map | 99 params: res.json() |
97 }); | 100 }) |
98 return map; | |
99 }) | 101 }) |
100 .catch((error: Response | any) => { | 102 .catch(console.error); // TODO Report error to user |
101 console.error(error); | |
102 return Observable.throw(error); | |
103 }); | |
104 } | 103 } |
105 | 104 |
106 load(libraryKey: string): void { | 105 load(libraryKey: string): void { |
107 this.worker.postMessage({method: 'import', params: libraryKey}); | 106 this.worker.postMessage({method: 'import', params: libraryKey}); |
108 } | 107 } |