Y
Y
Yuri Valdis2019-05-22 15:45:00
JavaScript
Yuri Valdis, 2019-05-22 15:45:00

How to stop an asynchronous queue?

Have a request

let CancelToken = axios.CancelToken; 
let cancel;

loadData: _.debounce(function (paramLogOut=false) {

        if (cancel != undefined && paramLogOut) {
          cancel();
          return true;
        }

        axios
          .post(params.url, params.data, {
            cancelToken: new CancelToken(function executor(c) {
              cancel = c;
            })
          })
          .then(response => {
            ... response
          })
          .catch((error) => {
            if (!axios.isCancel(error)) {
              this.showNoty('error', 'Что-то пошло не так... Данные не удалось загрузить');
              console.error(error);
            }
          })
      }, 75)

There is also, for example, a function to log out (log out):
logOut() {
        if (window.location.origin.search('127.0.0.1:9090') !== -1) {
          window.location.href = app.$axios.defaults.baseURL + '/Account/Logout';
        } else {
          window.location.href = '/Account/Logout';
        }
      }

The essence of the problem
When the user enters / makes possible settings, etc. ... the request works.
The request may take different times depending on the settings.
If at the moment the request is started, click on "Log out", then window.location.href waits for the end of this request, then the transition and decompression work ....
I used closing the request (axios cancel) so that the queue reaches the transition faster.
The request is cancelled, but window.href doesn't work right away. It does not immediately work when there is this request, even if it is already closed. In other cases, the transition occurs immediately.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question