Best way to handle timeouts on acknowledgements
Dear LearnBoost
Using the acknowledgements "feature" from socket.io works fine. Just in case the server does not respond (e.g. due to connection loss or high server load), the acknowledgement callback will never be fired. Therefore, I tried to implement timeouts for acknowledgements.
The following example is working, but it can happen that both, timeoutErrorFn and acknCallbackFn, will be executed. Is there an better, more common way to solve this problem? Do you think about adding timeouts to the "emit" as basic feature?
Thank you very much for any idea! Joschy
var timeoutId = setTimeout(timeoutErrorFn, 500);
var acknCallbackFn = function(err, userData){
clearTimeout(timeoutId)
//manage UserData
}
socket.emit('getUserData', acknCallbackFn);
If anyone lands here, please check the following module: https://www.npmjs.com/package/timeout-callback
Hope it helps :)
@jakubknejzlik Nice! Exactly what I was looking for.
@jakubknejzlik you solution appears to be for the server since, any idea on solution for cleint side??