Skip to content

Commit

Permalink
feat(client): Rename keepAlive option to lazyCloseTimeout
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Client `keepAlive` option has been renamed to `lazyCloseTimeout` in order to eliminate ambiguity with the client to server pings keep-alive option.
  • Loading branch information
enisdenjo committed Jun 8, 2021
1 parent 0550f0a commit 3c1f13c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions docs/interfaces/client.clientoptions.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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`
Expand All @@ -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`\>
Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Expand Up @@ -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?
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/tests/client.ts
Expand Up @@ -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,
});
Expand All @@ -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);
Expand Down

0 comments on commit 3c1f13c

Please sign in to comment.