【问题标题】:How to access the invocationId in SignalR core?如何访问 SignalR 核心中的 invocationId?
【发布时间】:2020-06-10 10:00:58
【问题描述】:

我正在 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 的响应。

【问题讨论】:

  • 你想防止在触发后短时间内调用/触发getData方法吗?如果您能对实际场景进行更多的澄清,我们就能更好地理解它。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-21
    • 2019-08-18
    • 1970-01-01
    • 2018-07-31
    • 2019-10-08
    • 2019-07-19
    • 2019-07-18
    • 1970-01-01
    相关资源
    最近更新 更多