How get Observable from etcd v2 watch

51 views Asked by At
_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:

  1. a request is sent
  2. 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))))))))))))))))))))

1

There are 1 answers

2
daflodedeing On

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?