Skip to content

Added support for consumer mode in client-side - #60

Merged
EmilianoSanchez merged 19 commits into
developmentfrom
consumer_mode_client_side
Nov 24, 2021
Merged

Added support for consumer mode in client-side#60
EmilianoSanchez merged 19 commits into
developmentfrom
consumer_mode_client_side

Conversation

@EmilianoSanchez

@EmilianoSanchez EmilianoSanchez commented Nov 4, 2021

Copy link
Copy Markdown
Contributor

Javascript commons library

What did you accomplish?

  • Added shared method to PluggableStorage, to use for multiple clients.
  • Fixed client.destroy method, to chain the storage.destroy promise result.
  • Fixed browser signal listener to handle the case where SyncManager is not defined (consumer mode).

How do we test the changes introduced in this PR?

  • Updated some UTs.

Extra Notes

@EmilianoSanchez EmilianoSanchez changed the title Added support for consumer mode in client-side [WIP] Added support for consumer mode in client-side Nov 11, 2021
Comment thread src/sdkFactory/index.ts
// or only instantiates submitters, and therefore it is not able to emit readiness events.
onReadyCb: (error) => {
if (error) return; // don't emit SDK_READY if storage failed to connect.
readinessManager.splits.emit(SDK_SPLITS_ARRIVED);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one will never be a shared instance right? and when we implement new flavors like node "client side", etc this will still be true?

Otherwise we should check about emitting a duplicated SPLITS_ARRIVED which might cause an SDK_UPDATE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When instantiating shared clients, a new onReadyCb is passed to the storage which only emits SDK_SEGMENTS_ARRIVED for that shared client. Therefore, no SDK_UPDATE event will be duplicated for the main client.

* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves inmediatelly.
*/
export function inMemoryWrapperFactory(): ICustomStorageWrapper & { _cache: Record<string, string | string[] | ISet<string>> } {
export function inMemoryWrapperFactory(connDelay?: number): ICustomStorageWrapper & { _cache: Record<string, string | string[] | ISet<string>>, _setConnDelay(connDelay: number): void } {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this parameter only used in testing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes Nico. At the moment, inMemoryWrapperFactory is only used in tests, but t is not inside a __tests__ folder, because those folders are not part of the uploaded NPM package, and so cannot be reused in other packages.

Comment thread src/storages/pluggable/index.ts Outdated
}).catch((e) => {
if (onReadyCb) onReadyCb(e || new Error('Error connecting wrapper'));
});
// emit SDK_READY event on main client

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this function about the ready event only, or about having the wrapper connect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onReadyCb is for having the ready event.
ATM:

  • InMemory and InLocalStorage only works with standalone mode, so they ignore the onReadyCb callback.
  • Redis and CustomStorage only works with consumer or consumer_partial mode, so they must use the onReadyCb callback to emit the ready event.

return {
...this,
// no-op destroy, to close the wrapper only when the main client is destroyed
destroy() { }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the assumption here is that given the nature of the client side API, we won't have a possible implementation where you might want to free up resources per "user"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nico, it is done this way to avoid calling the wrapper.close if a shared clients destroy method is called.

@EmilianoSanchez
EmilianoSanchez merged commit 721407e into development Nov 24, 2021
@EmilianoSanchez
EmilianoSanchez deleted the consumer_mode_client_side branch November 24, 2021 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants