Skip to content

[FSSDK-9416] Refactor dependent promises typing in client onReady #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ export class SingleEventQueue<K> implements EventQueue<K> {
this.sink = sink
}

start(): void {
start(): Promise<any> {
// no-op
return Promise.resolve()
}

stop(): Promise<any> {
Expand Down Expand Up @@ -114,9 +115,11 @@ export class DefaultEventQueue<K> implements EventQueue<K> {
this.started = false
}

start(): void {
start(): Promise<any> {
this.started = true
// dont start the timer until the first event is enqueued

return Promise.resolve();
}

stop(): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
export interface Managed {
start(): void
start(): Promise<any>

stop(): Promise<any>
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class LogTierV1EventProcessor implements EventProcessor {
}

public async start(): Promise<void> {
this.queue.start()
await this.queue.start()
this.unsubscribeNetInfo = addConnectionListener(this.connectionListener.bind(this))

await this.processPendingEvents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ export class LogTierV1EventProcessor implements EventProcessor {
}

async start(): Promise<void> {
this.queue.start()
await this.queue.start()
}
}
7 changes: 5 additions & 2 deletions packages/optimizely-sdk/lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ export default class Optimizely implements Client {

const eventProcessorStartedPromise = this.eventProcessor.start();

const dependentPromises: Array<Promise<any> | void> = [
const dependentPromises: Array<Promise<any>> = [
projectConfigManagerReadyPromise,
eventProcessorStartedPromise,
config.odpManager?.initPromise,
];

if (config.odpManager?.initPromise) {
dependentPromises.push(config.odpManager.initPromise);
}

this.readyPromise = Promise.all(dependentPromises).then(promiseResults => {
// If no odpManager exists yet, creates a new one
if (config.odpManager != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class ForwardingEventProcessor implements EventProcessor {
}
}

start(): void {}
start(): Promise<any> {
return Promise.resolve();
}

stop(): Promise<unknown> {
return Promise.resolve();
Expand Down