Skip to content

Commit 8ffee32

Browse files
author
Akos Kitta
committed
run core and lib index updates parallel.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 79503ef commit 8ffee32

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

arduino-ide-extension/src/node/core-client-provider.ts

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from './cli-protocol/cc/arduino/cli/commands/v1/commands_pb';
2121
import * as commandsGrpcPb from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
2222
import { NotificationServiceServer } from '../common/protocol';
23-
import { Deferred } from '@theia/core/lib/common/promise-util';
23+
import { Deferred, retry } from '@theia/core/lib/common/promise-util';
2424
import { Status as RpcStatus } from './cli-protocol/google/rpc/status_pb';
2525

2626
@injectable()
@@ -232,45 +232,15 @@ export class CoreClientProvider extends GrpcClientProvider<CoreClientProvider.Cl
232232
});
233233
}
234234

235-
protected async updateIndexes({
236-
client,
237-
instance,
238-
}: CoreClientProvider.Client): Promise<CoreClientProvider.Client> {
239-
// in a separate promise, try and update the index
240-
let indexUpdateSucceeded = true;
241-
for (let i = 0; i < 10; i++) {
242-
try {
243-
await this.updateIndex({ client, instance });
244-
indexUpdateSucceeded = true;
245-
break;
246-
} catch (e) {
247-
console.error(`Error while updating index in attempt ${i}.`, e);
248-
}
249-
}
250-
if (!indexUpdateSucceeded) {
251-
console.error('Could not update the index. Please restart to try again.');
252-
}
253-
254-
let libIndexUpdateSucceeded = true;
255-
for (let i = 0; i < 10; i++) {
256-
try {
257-
await this.updateLibraryIndex({ client, instance });
258-
libIndexUpdateSucceeded = true;
259-
break;
260-
} catch (e) {
261-
console.error(`Error while updating library index in attempt ${i}.`, e);
262-
}
263-
}
264-
if (!libIndexUpdateSucceeded) {
265-
console.error(
266-
'Could not update the library index. Please restart to try again.'
267-
);
268-
}
269-
270-
if (indexUpdateSucceeded && libIndexUpdateSucceeded) {
271-
this.notificationService.notifyIndexUpdated();
272-
}
273-
return { client, instance };
235+
protected async updateIndexes(
236+
client: CoreClientProvider.Client
237+
): Promise<CoreClientProvider.Client> {
238+
await Promise.all([
239+
retry(() => this.updateIndex(client), 50, 3),
240+
retry(() => this.updateLibraryIndex(client), 50, 3),
241+
]);
242+
this.notificationService.notifyIndexUpdated();
243+
return client;
274244
}
275245

276246
protected async updateLibraryIndex({

0 commit comments

Comments
 (0)