timeouts are not deleted once the monitored action is observed.
Here is my scenario
My client app emits an action AUTHENTICATE via web socket to the server. My remoteMiddleware which handles the socket connection sets a timeout to monitor for AUTHENTICATE_SUCCESS or AUTHENTICATE_FAIL and triggers AUTHENTICATE_FAIL with a 'Request timed out' message if no AUTHENTICATE_SUCCESS or AUTHENTICATE_FAIL action is received within a second. The emission of the AUTHENTICATE_FAIL ought to result in the timeout being cleared but it doesn't and I have to manually dispatch a removeTimeout action.
If the client receives an AUTHENTICATE_FAIL or AUTHENTICATE_SUCCESS action from the server the timeout is not automatically cleared either.
Looking into the code I see why.
if (monitor) {
clearTimeout(monitor.timeoutId)
monitor.timeoutId = setTimeout(monitor.toCall, monitor.timeout)
}
This correctly detects that there is a monitor for AUTHENTICATE_FAIL but instead of removing it, it simply resets the timeout. I'm at a loss to know why you'd do that instead of
if (monitor) {
clearTimeout(monitor.timeoutId)
delete watch[action]
}
which correctly removes the monitor for AUTHENTICATE_FAIL once it's been detected.
It won't remove the monitor for AUTHENTICATE_SUCCESS however. To do that the middleware needs to have a concept of linked actions, so it removes the monitors for both.
I suspect my use-case is quite different to how you envisioned this middleware to be used.
Hi @davesag, I haven't used this project in a while so its not obvious off the top of my head if what you're saying is correct or not, but I'll take a deeper look later tonight and check it out!
Hey guys,
I have the same requirement as OP. I want to use redux-timeout but I want it to remove the monitor when the action has been seen or on timeout without having to manually call removeTimeout(...).
Perhaps we can make this into an argument when you create the timeout?
i.e:
addTimeout(1000, ACTION_TO_WATCH, save, removeTimeoutOnAction)
So people have the option to remove the timeout or to reset it once the action has been seen.