Search code examples
javascriptasp.net-core-signalrsignalr-client

How to access the invocationId in SignalR core?


I'm creating an app with SignalR Core on Azure. Now I need to match the invoked request with the returned value and callback. I would like to use the invocationId to make sure the method that will be executed is the latest invoked request. To avoid as happens in the attached image.

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);
    });

When the getData is invoked multiple times in a short interval I would like to be sure to use the right response. So the response with invocationId 8 needs to be ignored and only the response with invocationId 9 is used. enter image description here


Solution

  • I've implemented a new id that is send on the request and can be validated when the value is returned.