Skip to content

Commit 76dc55a

Browse files
mbardauskasMartynas Bardauskas
andauthored
make timeout before connection configurable (#16)
* make timeout before connection configurable * add missing type --------- Co-authored-by: Martynas Bardauskas <martynas.bardauskas@eneba.com>
1 parent 881670f commit 76dc55a

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ new EventSource(url: string | URL, options?: EventSourceOptions);
187187
const options: EventSourceOptions = {
188188
method: 'GET'; // Request method. Default: GET
189189
timeout: 0; // Time after which the connection will expire without any activity: Default: 0 (no timeout)
190+
timeoutBeforeConnection: 500; // Time to wait before initial connection is made: Default: 500ms
190191
headers: {}; // Your request headers. Default: {}
191192
body: undefined; // Your request body sent on connection: Default: undefined
192193
debug: false; // Show console.debug messages for debugging purpose. Default: false

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface EventSourceOptions {
5050
body?: any;
5151
debug?: boolean;
5252
pollingInterval?: number;
53+
timeoutBeforeConnection?: number;
5354
}
5455

5556
export type EventSourceEvent = MessageEvent | OpenEvent | CloseEvent | TimeoutEvent | ErrorEvent | ExceptionEvent;

src/EventSource.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class EventSource {
2323
this.headers = options.headers || {};
2424
this.body = options.body || undefined;
2525
this.debug = options.debug || false;
26+
this.timeoutBeforeConnection = options.timeoutBeforeConnection ?? 500;
2627

2728
this._xhr = null;
2829
this._pollTimer = null;
@@ -37,7 +38,7 @@ class EventSource {
3738
this.url = url;
3839
}
3940

40-
this._pollAgain(500);
41+
this._pollAgain(this.timeoutBeforeConnection);
4142
}
4243

4344
_pollAgain(time) {

0 commit comments

Comments
 (0)