Skip to content
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

perf: perform setup requests in parallel #454

Merged
merged 2 commits into from
Sep 9, 2023
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
17 changes: 9 additions & 8 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,23 +392,24 @@
*/
async start(options?: PollingOptions) {
// Perform setup
const setup: Promise<void>[] = [];

Check warning on line 395 in src/bot.ts

View check run for this annotation

Codecov / codecov/patch

src/bot.ts#L395

Added line #L395 was not covered by tests
rojvv marked this conversation as resolved.
Show resolved Hide resolved
if (!this.isInited()) {
await this.init(this.pollingAbortController?.signal);
setup.push(this.init(this.pollingAbortController?.signal));

Check warning on line 397 in src/bot.ts

View check run for this annotation

Codecov / codecov/patch

src/bot.ts#L397

Added line #L397 was not covered by tests
}
if (this.pollingRunning) {
await Promise.all(setup);

Check warning on line 400 in src/bot.ts

View check run for this annotation

Codecov / codecov/patch

src/bot.ts#L400

Added line #L400 was not covered by tests
rojvv marked this conversation as resolved.
Show resolved Hide resolved
debug("Simple long polling already running!");
return;
} else {
this.pollingRunning = true;
this.pollingAbortController = new AbortController();
}
await withRetries(
() =>
this.api.deleteWebhook({
drop_pending_updates: options?.drop_pending_updates,
}, this.pollingAbortController?.signal),
this.pollingAbortController?.signal,
);
setup.push(withRetries(async () => {
await this.api.deleteWebhook({
drop_pending_updates: options?.drop_pending_updates,
}, this.pollingAbortController?.signal);
}, this.pollingAbortController?.signal));
await Promise.all(setup);

Check warning on line 412 in src/bot.ts

View check run for this annotation

Codecov / codecov/patch

src/bot.ts#L407-L412

Added lines #L407 - L412 were not covered by tests

// All async ops of setup complete, run callback
await options?.onStart?.(this.botInfo);
Expand Down
Loading