Skip to content
Merged
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
9 changes: 9 additions & 0 deletions packages/apify/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
log.debug(
`Waiting for all event listeners to complete their execution (with ${options.timeoutSecs} seconds timeout)`,
);

if (options.exit) {
// `addTimeoutToPromise` is a cooperative timeout. This ensures that the process exits
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, if something hogs the event loop with something CPU-intensive, the setTimeout won't fire, but this surely is better than the previous state

// after the timeout, even if the event listeners don't trigger the timeout.
setTimeout(() => {
process.exit(options.exitCode);
}, options.timeoutSecs * 1000);
}

await addTimeoutToPromise(
async () => {
await events.waitForAllListenersToComplete();
Expand Down
Loading