Open huan opened 6 years ago
Not sure I see the point of this, it's very easy to implement directly in onMessage
or with a small helper:
import pTimeout from 'p-timeout'
const addTimeout = (onMessage, delay) => function () {
return pTimeout(onMessage.apply(this, arguments), delay)
}
@julien-f It's a brilliant way to set the timeout for the JSON RPC server side Peer.
However, I'm facing a situation that I can not set the timeout for the client-side Peer.
According to the above code, if my server will not response me, then it seems that I have no way to control my request()
to fail after a period of time?
Currently, we can only call
failPendingRequests()
to make all the pending requests fail.Sometimes it's better to set a timeout value and let the request failed automatically when it runs time out.
The simplest modification should be to add a
timeout
argument tofailPendingRequests(timeout: number)
, which can be called period and clean the timeout-ed requests.A better way to implement it might integrate the timeout with the Peer class. For example: