_watch(key: string): Observable<AxiosResponse<any>> {
let url: string = `${this.buildUrl(key)}?wait=true&recursive=true`;
return this.httpService.get(url)
.pipe(
map((resp) => resp),
tap(data => console.log(data))
)
}
watch(key: string) {
this._watch(key).subscribe({
next: (v) => console.log(v),
error: (err) => {
if (!err.response) return new EtcdConnectionError();
let data = err.response.data;
switch (data.errorCode) {
// https://etcd.io/docs/v2.3/errorcode/
case 100:
return new EtcdNotFoundError(key);
default:
return new EtcdCommonError(data.message);
}
},
complete: () => console.info('complete')
})
}
I vaguely understand how to interact with Observable, I would be grateful if you tell me how to figure it out more, I read the basic documentation.
The code works +/- like this:
- a request is sent
- if there are changes, a response comes and so on in a circle
what should i do to get periodic status, or what is my mistake?
UPD
watch(key: string) {
return this._watch(key).subscribe({
I forgot to indicate the return
and suffered with this day))))))))))))))))))))
You make a http request to etcd api. When there is a response you receive the repsonse via
next
function. Then the observable completes.Do you want to poll the api periodically and write the results to an observable?