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 to failPendingRequests(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:
interface PeerOptions {
timeout: number
}
class Peer {
constructor(public options: PeerOptions) {
}
// request will be rejected if it did not get any response from the server after timeout milliseconds.
}
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
timeoutargument 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: