如何访问SignalR核心中的invocationId?

时间:2020-06-10 10:00:58

标签: javascript asp.net-core-signalr signalr-client

我正在Azure上用SignalR Core创建一个应用程序。现在,我需要将调用的请求与返回的值和回调进行匹配。我想使用invocationId来确保将要执行的方法是最新调用的请求。为了避免在附件中出现这种情况。

var _this.latestInvokeId = ??
connection.invoke('getData', _this.ID)
    .then(function (data) {
        if(this.invocationId === _this.latestInvokeId)
            console.log('Use the data', data)
    })
    .catch(function (error) {
        console.log(error);
    });

在短时间内多次调用getData时,我想确保使用正确的响应。因此,需要忽略具有invocationId 8的响应,而仅使用具有invocationId 9的响应。 enter image description here

1 个答案:

答案 0 :(得分:0)

我实现了一个新的ID,该ID在请求中发送,并且可以在返回值时进行验证。

相关问题