Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to handle timeouts on acknowledgements #828

Closed
jjoschyy opened this issue Apr 11, 2012 · 3 comments
Closed

Best way to handle timeouts on acknowledgements #828

jjoschyy opened this issue Apr 11, 2012 · 3 comments

Comments

@jjoschyy
Copy link

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);
@jakubknejzlik
Copy link

If anyone lands here, please check the following module:
https://www.npmjs.com/package/timeout-callback

Hope it helps :)

@nicopeeters
Copy link

@jakubknejzlik Nice! Exactly what I was looking for.

@Mrjaid
Copy link

Mrjaid commented Sep 3, 2017

@jakubknejzlik you solution appears to be for the server since, any idea on solution for cleint side??

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@jjoschyy @jakubknejzlik @nicopeeters @Mrjaid and others