Skip to content

Commit f726167

Browse files
perf: don't await final status message (#497)
This saves about 25ms at the end of each run. Related to discussion - apify/crawlee#3207 (comment) I did about 700 runs and it worked in each. Without any sleep it didn't print it on platform. The actual delay is about 2-3ms, which is probably the networking code executing.
1 parent 8753957 commit f726167

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/apify/src/actor.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
583583
}
584584

585585
if (options.statusMessage != null) {
586-
await this.setStatusMessage(options.statusMessage, {
587-
isStatusMessageTerminal: true,
588-
level: options.exitCode! > 0 ? 'ERROR' : 'INFO',
589-
});
586+
const statusMessagePromise = this.setStatusMessage(
587+
options.statusMessage,
588+
{
589+
isStatusMessageTerminal: true,
590+
level: options.exitCode! > 0 ? 'ERROR' : 'INFO',
591+
},
592+
);
593+
// Waiting 1ms is enough for the network request to be sent. We don't need to wait for the response.
594+
await Promise.race([statusMessagePromise, sleep(1)]);
590595
}
591596
},
592597
options.timeoutSecs * 1000,

0 commit comments

Comments
 (0)