-1

I have an expressjs/socket.io server supporting my web application and am presented with the following challenge:

One user may request access to a resource owned by another user, who can grant/deny the request. However, if they ignore the request, or a network blip causes the request to not be delivered, I would like to have a mechanism by which the request expires, automatically informing the requester.

I could just use setTimeout with a callback that checks if the request has received a response after X time, but that feels so basic - I've never done anything like this before so I'm not sure if there's a more "correct" way.

2
  • 1
    setTimeout() is the usual way to implement a timeout in nodejs if it doesn't need to persist across server restarts. Nodejs is particularly efficient for large numbers of timers so having a bunch of timers is not an issue.
    – jfriend00
    2 days ago
  • If by "basic" you mean "simple". When does simplicity became a problem? Does it solve the problem? Yes? Then, why not? The alternative can be more sophisticated but it doesn't make it better per se.
    – Laiv
    yesterday

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.