Send HTTPclient post request but dont wait for response and subscribe when backend call sends response back

女生的网名这么多〃 提交于 2021-01-28 07:44:27

问题


I am new to Angular and RxJS operators. I need help in one of the scenario in which I upload multiple documents at once in the backend (Rest API).

Processing the documents takes time in backend my my observable gets timeout in 2 minutes.

Now I am thinking of the solution in which I will send the post request to backend and will not wait for the response. And subscribe whenever response is ready by backend.

Please suggest if my approach is ok ? and how to achieve it in angular 8 with and Rxjs operators.

below is the my httpclient post method:

createNewVersion(formData: FormData) {
    let payload = new HttpParams();
    return this.httpClient
      .post(endpoint, formData, { params: payload }).subscribe((response: boolean) => {
        this.isLoading = false;
        if (response != null)
          this.observableVersion.next(true);
      });
  }

Currently I am facing timeout error after 2 minutes when response doesnt comes from backend that is why I have to change the logic.

Please help.

来源:https://stackoverflow.com/questions/64659213/send-httpclient-post-request-but-dont-wait-for-response-and-subscribe-when-backe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!