diff --git a/docs/interfaces/client.clientoptions.md b/docs/interfaces/client.clientoptions.md index 213dca8b..ea69fcca 100644 --- a/docs/interfaces/client.clientoptions.md +++ b/docs/interfaces/client.clientoptions.md @@ -15,8 +15,8 @@ Configuration used for the GraphQL over WebSocket client. - [isFatalConnectionProblem](client.clientoptions.md#isfatalconnectionproblem) - [jsonMessageReplacer](client.clientoptions.md#jsonmessagereplacer) - [jsonMessageReviver](client.clientoptions.md#jsonmessagereviver) -- [keepAlive](client.clientoptions.md#keepalive) - [lazy](client.clientoptions.md#lazy) +- [lazyCloseTimeout](client.clientoptions.md#lazyclosetimeout) - [on](client.clientoptions.md#on) - [onNonLazyError](client.clientoptions.md#onnonlazyerror) - [retryAttempts](client.clientoptions.md#retryattempts) @@ -118,18 +118,6 @@ out of the incoming JSON. ___ -### keepAlive - -• `Optional` **keepAlive**: `number` - -How long should the client wait before closing the socket after the last oparation has -completed. This is meant to be used in combination with `lazy`. You might want to have -a calmdown time before actually closing the connection. Kinda' like a lazy close "debounce". - -**`default`** 0 // close immediately - -___ - ### lazy • `Optional` **lazy**: `boolean` @@ -144,6 +132,18 @@ the subscription sink's `error` to handle errors. ___ +### lazyCloseTimeout + +• `Optional` **lazyCloseTimeout**: `number` + +How long should the client wait before closing the socket after the last oparation has +completed. This is meant to be used in combination with `lazy`. You might want to have +a calmdown time before actually closing the connection. Kinda' like a lazy close "debounce". + +**`default`** 0 // close immediately + +___ + ### on • `Optional` **on**: `Partial`<`Object`\> diff --git a/src/client.ts b/src/client.ts index 903c0547..2753dcad 100644 --- a/src/client.ts +++ b/src/client.ts @@ -172,7 +172,7 @@ export interface ClientOptions { * * @default 0 // close immediately */ - keepAlive?: number; + lazyCloseTimeout?: number; /** * How many times should the client try to reconnect on abnormal socket closure before it errors out? * @@ -277,7 +277,7 @@ export function createClient(options: ClientOptions): Client { connectionParams, lazy = true, onNonLazyError = console.error, - keepAlive = 0, + lazyCloseTimeout = 0, retryAttempts = 5, retryWait = async function randomisedExponentialBackoff(retries) { let retryDelay = 1000; // start with 1s delay @@ -495,14 +495,14 @@ export function createClient(options: ClientOptions): Client { if (!locks) { // and if no more locks are present, complete the connection const complete = () => socket.close(1000, 'Normal Closure'); - if (isFinite(keepAlive) && keepAlive > 0) { + if (isFinite(lazyCloseTimeout) && lazyCloseTimeout > 0) { // if the keepalive is set, allow for the specified calmdown time and // then complete. but only if no lock got created in the meantime and // if the socket is still open setTimeout(() => { if (!locks && socket.readyState === WebSocketImpl.OPEN) complete(); - }, keepAlive); + }, lazyCloseTimeout); } else { // otherwise complete immediately complete(); diff --git a/src/tests/client.ts b/src/tests/client.ts index cd0a2f61..e2d77b65 100644 --- a/src/tests/client.ts +++ b/src/tests/client.ts @@ -774,13 +774,13 @@ describe('lazy', () => { await server.waitForClientClose(); }); - it('should disconnect after the keepAlive has passed after last unsubscribe', async () => { + it('should disconnect after the lazyCloseTimeout has passed after last unsubscribe', async () => { const { url, ...server } = await startTServer(); const client = createClient({ url, lazy: true, // default - keepAlive: 20, + lazyCloseTimeout: 20, retryAttempts: 0, onNonLazyError: noop, }); @@ -798,7 +798,7 @@ describe('lazy', () => { // everyone unsubscribed sub.dispose(); - // still connected because of the keepAlive + // still connected because of the lazyCloseTimeout await server.waitForClientClose(() => { fail("Client shouldn't have closed"); }, 10);