Skip to content

Commit c2c88de

Browse files
committed
fix: Wait for the pricing service to be ready
1 parent daf475a commit c2c88de

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/pricing/pricing.service.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,30 @@ export class PricingService implements OnModuleInit {
2525
private worker: Worker | null = null;
2626
private requestPortMessageId = 0;
2727

28+
private setReady!: () => void;
29+
readonly isReady: Promise<void>;
30+
2831
constructor(
2932
private readonly configService: ConfigService,
3033
private readonly loggerService: LoggerService,
31-
) {}
34+
) {
35+
this.isReady = this.initializeIsReady();
36+
}
3237

3338
onModuleInit() {
3439
this.loggerService.info(`Starting Pricing worker...`);
3540

3641
this.initializeWorker();
3742

3843
this.initiateIntervalStatusLog();
44+
45+
this.setReady();
46+
}
47+
48+
private initializeIsReady(): Promise<void> {
49+
return new Promise<void>((resolve) => {
50+
this.setReady = resolve;
51+
});
3952
}
4053

4154
private initializeWorker(): void {
@@ -139,6 +152,8 @@ export class PricingService implements OnModuleInit {
139152

140153
async attachToPricing(): Promise<MessagePort> {
141154

155+
await this.isReady;
156+
142157
const worker = this.worker;
143158
if (worker == undefined) {
144159
throw new Error(`Pricing worker is null.`);

0 commit comments

Comments
 (0)