Skip to content

Commit

Permalink
feat: make eager connections as default unless otherwise specified in…
Browse files Browse the repository at this point in the history
… factory methpds (#732)

* feat: make eager connections as default unless otherwise specified in factory methpds
  • Loading branch information
pratik151192 authored Aug 17, 2023
1 parent 76a2ac8 commit 170885f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions packages/client-sdk-nodejs/src/cache-client-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export interface EagerCacheClientProps extends CacheClientProps {
/**
* The time in seconds to wait for a client to establish a connection to Momento.
*
* If present, the client will eagerly create its connection to Momento at construction. It will wait until the
* connection is established, or until the timout runs out. It the timeout runs out, the client will be valid to use,
* but it may still be connecting in the background.
* The behavior to establish an eager connection is enabled by default. If this value is set, the client will eagerly
* create its connection to Momento at construction. It will wait until the connection is established, or until the
* timeout runs out. It the timeout runs out, the client will be valid to use, but it may still be connecting in the background.
*
* Override this value to 0 if you want to disable eager connections.
*/
eagerConnectTimeout?: number;
}
Expand Down
14 changes: 7 additions & 7 deletions packages/client-sdk-nodejs/src/cache-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {range} from '@gomomento/sdk-core/dist/src/internal/utils';
import {ICacheClient} from '@gomomento/sdk-core/dist/src/clients/ICacheClient';
import {AbstractCacheClient} from '@gomomento/sdk-core/dist/src/internal/clients/cache/AbstractCacheClient';

const EAGER_CONNECITON_DEFAULT_TIMEOUT_SECONDS = 30;
/**
* Momento Cache Client.
*
Expand All @@ -23,7 +24,6 @@ import {AbstractCacheClient} from '@gomomento/sdk-core/dist/src/internal/clients
export class CacheClient extends AbstractCacheClient implements ICacheClient {
private readonly logger: MomentoLogger;
private readonly notYetAbstractedControlClient: ControlClient;

/**
* Creates an instance of CacheClient.
* @param {CacheClientProps} props configuration and credentials for creating a CacheClient.
Expand Down Expand Up @@ -57,14 +57,14 @@ export class CacheClient extends AbstractCacheClient implements ICacheClient {
*/
static async create(props: EagerCacheClientProps): Promise<CacheClient> {
const client = new CacheClient(props);
if (
props.eagerConnectTimeout !== null &&
const timeout =
props.eagerConnectTimeout !== undefined
) {
? props.eagerConnectTimeout
: EAGER_CONNECITON_DEFAULT_TIMEOUT_SECONDS;
// client need to explicitly set the value as 0 to disable eager connection.
if (props.eagerConnectTimeout !== 0) {
await Promise.all(
client.dataClients.map(dc =>
(dc as DataClient).connect(props.eagerConnectTimeout)
)
client.dataClients.map(dc => (dc as DataClient).connect(timeout))
);
}
return client;
Expand Down

0 comments on commit 170885f

Please sign in to comment.