Skip to content

Commit e2341e4

Browse files
committed
Feat: Support error parameter in nextRetryTimeout
1 parent 3692076 commit e2341e4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/stream/TweetStream.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface IConnectTweetStreamParams {
2222
}
2323

2424
/** Returns a number of milliseconds to wait for {tryOccurence} (starting from 1) */
25-
export type TStreamConnectRetryFn = (tryOccurence: number) => number;
25+
export type TStreamConnectRetryFn = (tryOccurence: number, error?: any) => number;
2626

2727
// In seconds
2828
const basicRetriesAttempt = [5, 15, 30, 60, 90, 120, 180, 300, 600, 900];
@@ -261,7 +261,7 @@ export class TweetStream<T = any> extends EventEmitter {
261261
// Only make a reconnection attempt if autoReconnect is true!
262262
// Otherwise, let error be propagated
263263
if (this.autoReconnect) {
264-
this.makeAutoReconnectRetry(0);
264+
this.makeAutoReconnectRetry(0, e);
265265
} else {
266266
throw e;
267267
}
@@ -327,12 +327,12 @@ export class TweetStream<T = any> extends EventEmitter {
327327
message: `Reconnect error - ${retryOccurence + 1} attempts made yet.`,
328328
});
329329

330-
this.makeAutoReconnectRetry(retryOccurence);
330+
this.makeAutoReconnectRetry(retryOccurence, e);
331331
}
332332
}
333333

334-
protected makeAutoReconnectRetry(retryOccurence: number) {
335-
const nextRetry = this.nextRetryTimeout(retryOccurence + 1);
334+
protected makeAutoReconnectRetry(retryOccurence: number, error: any) {
335+
const nextRetry = this.nextRetryTimeout(retryOccurence + 1, error);
336336

337337
this.retryTimeout = setTimeout(() => {
338338
this.onConnectionError(retryOccurence + 1);

0 commit comments

Comments
 (0)