Skip to content

Commit ef3a0c5

Browse files
authored
fix: use correct event manager for actor methods (#49)
1 parent 82937dd commit ef3a0c5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/apify/src/actor.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ export class Actor<Data extends Dictionary = Dictionary> {
168168
// reset global config instance to respect APIFY_ prefixed env vars
169169
CoreConfiguration.globalConfig = Configuration.getGlobalConfig();
170170

171-
await this.eventManager.init();
172-
173171
if (this.isAtHome()) {
174172
this.config.set('availableMemoryRatio', 1);
175173
this.config.set('disableBrowserSandbox', true); // for browser launcher, adds `--no-sandbox` to args
@@ -179,6 +177,9 @@ export class Actor<Data extends Dictionary = Dictionary> {
179177
this.config.useStorageClient(options.storage);
180178
}
181179

180+
// Init the event manager the config uses
181+
await this.config.getEventManager().init();
182+
182183
await purgeDefaultStorages(this.config);
183184
Configuration.storage.enterWith(this.config);
184185
}
@@ -193,15 +194,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
193194
options.timeoutSecs ??= 30;
194195

195196
// Close the event manager and emit the final PERSIST_STATE event
196-
await this.eventManager.close();
197+
await this.config.getEventManager().close();
197198

198199
// Emit the exit event
199-
this.eventManager.emit(EventType.EXIT, options);
200+
this.config.getEventManager().emit(EventType.EXIT, options);
200201

201202
// Wait for all event listeners to be processed
202203
log.debug(`Waiting for all event listeners to complete their execution (with ${options.timeoutSecs} seconds timeout)`);
203204
await addTimeoutToPromise(
204-
() => this.eventManager.waitForAllListenersToComplete(),
205+
() => this.config.getEventManager().waitForAllListenersToComplete(),
205206
options.timeoutSecs * 1000,
206207
`Waiting for all event listeners to complete their execution timed out after ${options.timeoutSecs} seconds`,
207208
);
@@ -245,14 +246,14 @@ export class Actor<Data extends Dictionary = Dictionary> {
245246
* @ignore
246247
*/
247248
on(event: EventTypeName, listener: (...args: any[]) => any): void {
248-
this.eventManager.on(event, listener);
249+
this.config.getEventManager().on(event, listener);
249250
}
250251

251252
/**
252253
* @ignore
253254
*/
254255
off(event: EventTypeName, listener?: (...args: any[]) => any): void {
255-
this.eventManager.off(event, listener);
256+
this.config.getEventManager().off(event, listener);
256257
}
257258

258259
/**

0 commit comments

Comments
 (0)