Aurelia HttpClient取消请求

Aurelia HttpClient取消请求,aurelia,Aurelia,我正在尝试构建一个自动完成组件,并希望它在服务器键入未解析的请求时取消这些请求 我在HttpClient的文档中找不到关于这方面的文档。它提到它是可取消的(不像fetch),但没有提到如何取消 目前我有一个我相当盲目地拼凑起来的,毫不奇怪它甚至没有中止请求: async searchTermChanged(newValue, oldValue) { if (newValue.length < 3) return; if (this.promises.le

我正在尝试构建一个自动完成组件,并希望它在服务器键入未解析的请求时取消这些请求

我在HttpClient的文档中找不到关于这方面的文档。它提到它是可取消的(不像fetch),但没有提到如何取消

目前我有一个我相当盲目地拼凑起来的,毫不奇怪它甚至没有中止请求:

async searchTermChanged(newValue, oldValue) {   
    if (newValue.length < 3)
      return;

    if (this.promises.length) {
       this.promises.forEach(x => x.abort());
       //should probably remove too
    }

    var promise = this.httpClient.post(this.endpoint, { SearchTerm: newValue });
    this.promises.push(promise);

    var data = await promise;

    var response = JSON.parse(data.response);

    this.results = response;
  }
}
async searchTermChanged(newValue,oldValue){
如果(newValue.length<3)
返回;
if(this.promises.length){
this.promises.forEach(x=>x.abort());
//可能也应该删除
}
var promise=this.httpClient.post(this.endpoint,{SearchTerm:newValue});
这个。承诺。推动(承诺);
var数据=等待承诺;
var response=JSON.parse(data.response);
结果=响应;
}
}

在哪里可以找到有关如何提出可取消请求的更多信息?我的google fu让我失望。

看起来你可以做到:

this.client["pendingRequests"].forEach(request => {
   request.abort();
});
我必须执行
[“pendingRequests”]
,因为我使用的是TypeScript,数组似乎不在定义范围内


注意:我还在每个自动完成中使用作用域HttpClient,这样当它取消所有以前的请求时,它不会意外地取消应用程序正在请求的其他请求。

我使用它来中止我的请求,但现在收到警告
警告:承诺被拒绝,但没有错误:[object]
。你也有这个问题吗?