Skip to content

Commit 3058aa1

Browse files
authored
add higher and configurable reconnect time (#235)
* add higher and configurable reconnect time * fix tests
1 parent 5a016f3 commit 3058aa1

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.changeset/plain-eagles-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools-event-client': patch
3+
---
4+
5+
increase minimum reconnection time and allow it to be configurable on event bus client

packages/event-bus-client/src/plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ export class EventClient<
6464
pluginId,
6565
debug = false,
6666
enabled = true,
67+
reconnectEveryMs = 1000,
6768
}: {
6869
pluginId: TPluginId
6970
debug?: boolean
70-
71+
reconnectEveryMs?: number
7172
enabled?: boolean
7273
}) {
7374
this.#pluginId = pluginId
@@ -78,7 +79,7 @@ export class EventClient<
7879
this.#queuedEvents = []
7980
this.#connected = false
8081
this.#connectIntervalId = null
81-
this.#connectEveryMs = 500
82+
this.#connectEveryMs = reconnectEveryMs
8283
}
8384

8485
private startConnectLoop() {

packages/event-bus-client/tests/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe('EventClient', () => {
208208

209209
bus.start()
210210
// wait to connect to the bus
211-
await new Promise((resolve) => setTimeout(resolve, 500))
211+
await new Promise((resolve) => setTimeout(resolve, 1000))
212212
expect(eventHandler).toHaveBeenCalledWith({
213213
type: 'test:event',
214214
payload: { foo: 'bar' },
@@ -221,6 +221,7 @@ describe('EventClient', () => {
221221
const client = new EventClient({
222222
debug: false,
223223
pluginId: 'test',
224+
reconnectEveryMs: 500,
224225
})
225226
const eventHandler = vi.fn()
226227
client.onAllPluginEvents(eventHandler)

0 commit comments

Comments
 (0)