Added support for consumer mode in client-side - #60
Conversation
This reverts commit 9dfccd7.
| // 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 } { |
There was a problem hiding this comment.
Is this parameter only used in testing?
There was a problem hiding this comment.
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.
| }).catch((e) => { | ||
| if (onReadyCb) onReadyCb(e || new Error('Error connecting wrapper')); | ||
| }); | ||
| // emit SDK_READY event on main client |
There was a problem hiding this comment.
is this function about the ready event only, or about having the wrapper connect?
There was a problem hiding this comment.
onReadyCb is for having the ready event.
ATM:
- InMemory and InLocalStorage only works with
standalonemode, so they ignore theonReadyCbcallback. - Redis and CustomStorage only works with
consumerorconsumer_partialmode, so they must use theonReadyCbcallback to emit the ready event.
| return { | ||
| ...this, | ||
| // no-op destroy, to close the wrapper only when the main client is destroyed | ||
| destroy() { } |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
Nico, it is done this way to avoid calling the wrapper.close if a shared clients destroy method is called.
Added support for partial consumer mode
Javascript commons library
What did you accomplish?
client.destroymethod, to chain thestorage.destroypromise result.How do we test the changes introduced in this PR?
Extra Notes