Aurelia取消了具体要求

问题描述 投票:1回答:1

有没有办法取消特定的请求?我跟着this取消了请求,但如果我有多个请求怎么办,我怎么能确定我没有取消错误的请求呢?有没有办法取消特定的请求?

目前它的工作原理如下:

async getEmployeeListBySearchword(searchword: string): Promise<IMember[]> {
    try {
        const response = await this.get(`employees/${decodeURIComponent(searchword)}`);
        return JSON.parse(response['response']) as Promise<IMember[]>;
    }catch(e){
        if(e.responseType != "abort") {
            console.log(e);
        }
    }
}

cancelRequest(){
    if(AbortableHttpService.http){
        AbortableHttpService.http['pendingRequests'].forEach(request =>{
            request.abort();
        });
    }
}

http设置代码被包装到一个名为AbortableHttpService的类中,它创建HttpClient并对其进行配置并为其隐藏一些样板代码。

aurelia aurelia-http-client
1个回答
2
投票

我不确定这是否有记录,但在aurelia-http-client源代码中,我看到cancel / abort函数被添加到您发出请求时收到的承诺中。

因此,调用response.cancel()response.abort()应该有效。

© www.soinside.com 2019 - 2024. All rights reserved.