mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 11:56:36 +00:00
Fixed a race condition when requestng core client.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
e14ac4a396
commit
50c1c7dcb2
@ -9,7 +9,9 @@
|
|||||||
"@theia/filesystem": "next",
|
"@theia/filesystem": "next",
|
||||||
"@theia/languages": "next",
|
"@theia/languages": "next",
|
||||||
"@theia/monaco": "next",
|
"@theia/monaco": "next",
|
||||||
"@theia/workspace": "next"
|
"@theia/workspace": "next",
|
||||||
|
"@types/p-queue": "^3.2.1",
|
||||||
|
"p-queue": "^5.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"generate-protoc": "./scripts/generate-protoc.sh",
|
"generate-protoc": "./scripts/generate-protoc.sh",
|
||||||
|
@ -8,10 +8,13 @@ import URI from '@theia/core/lib/common/uri';
|
|||||||
import { CoreClientProvider, Client } from './core-client-provider';
|
import { CoreClientProvider, Client } from './core-client-provider';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as PQueue from 'p-queue';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class CoreClientProviderImpl implements CoreClientProvider {
|
export class CoreClientProviderImpl implements CoreClientProvider {
|
||||||
|
|
||||||
|
protected readonly clientRequestQueue = new PQueue({ autoStart: true, concurrency: 1 });
|
||||||
|
|
||||||
@inject(FileSystem)
|
@inject(FileSystem)
|
||||||
protected readonly fileSystem: FileSystem;
|
protected readonly fileSystem: FileSystem;
|
||||||
|
|
||||||
@ -21,9 +24,11 @@ export class CoreClientProviderImpl implements CoreClientProvider {
|
|||||||
protected clients = new Map<string, Client>();
|
protected clients = new Map<string, Client>();
|
||||||
|
|
||||||
async getClient(workspaceRootOrResourceUri?: string): Promise<Client> {
|
async getClient(workspaceRootOrResourceUri?: string): Promise<Client> {
|
||||||
|
return this.clientRequestQueue.add(() => new Promise<Client>(async resolve => {
|
||||||
const roots = await this.workspaceServiceExt.roots();
|
const roots = await this.workspaceServiceExt.roots();
|
||||||
if (!workspaceRootOrResourceUri) {
|
if (!workspaceRootOrResourceUri) {
|
||||||
return this.getOrCreateClient(roots[0]);
|
resolve(this.getOrCreateClient(roots[0]));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const root = roots
|
const root = roots
|
||||||
.sort((left, right) => right.length - left.length) // Longest "paths" first
|
.sort((left, right) => right.length - left.length) // Longest "paths" first
|
||||||
@ -32,9 +37,11 @@ export class CoreClientProviderImpl implements CoreClientProvider {
|
|||||||
if (!root) {
|
if (!root) {
|
||||||
console.warn(`Could not retrieve the container workspace root for URI: ${workspaceRootOrResourceUri}.`);
|
console.warn(`Could not retrieve the container workspace root for URI: ${workspaceRootOrResourceUri}.`);
|
||||||
console.warn(`Falling back to ${roots[0]}`);
|
console.warn(`Falling back to ${roots[0]}`);
|
||||||
return this.getOrCreateClient(roots[0]);
|
resolve(this.getOrCreateClient(roots[0]));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return this.getOrCreateClient(root.toString());
|
resolve(this.getOrCreateClient(root.toString()));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getOrCreateClient(rootUri: string): Promise<Client> {
|
protected async getOrCreateClient(rootUri: string): Promise<Client> {
|
||||||
|
@ -1,10 +1,23 @@
|
|||||||
import { injectable } from 'inversify';
|
import { injectable, inject } from 'inversify';
|
||||||
import { Library, LibraryService } from '../common/protocol/library-service';
|
import { Library, LibraryService } from '../common/protocol/library-service';
|
||||||
|
import { CoreClientProvider } from './core-client-provider';
|
||||||
|
import { LibrarySearchReq, LibrarySearchResp } from './cli-protocol/lib_pb';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class LibraryServiceImpl implements LibraryService {
|
export class LibraryServiceImpl implements LibraryService {
|
||||||
|
|
||||||
|
@inject(CoreClientProvider)
|
||||||
|
protected readonly coreClientProvider: CoreClientProvider;
|
||||||
|
|
||||||
async search(options: { query?: string; }): Promise<{ items: Library[] }> {
|
async search(options: { query?: string; }): Promise<{ items: Library[] }> {
|
||||||
|
const { client, instance } = await this.coreClientProvider.getClient();
|
||||||
|
|
||||||
|
const req = new LibrarySearchReq();
|
||||||
|
req.setQuery(options.query || '');
|
||||||
|
req.setInstance(instance);
|
||||||
|
const resp = await new Promise<LibrarySearchResp>((resolve, reject) => client.librarySearch(req, (err, resp) => !!err ? reject(err) : resolve(resp)));
|
||||||
|
console.log(resp.getSearchOutputList());
|
||||||
|
|
||||||
const { query } = options;
|
const { query } = options;
|
||||||
const allItems: Library[] = [
|
const allItems: Library[] = [
|
||||||
<Library>{
|
<Library>{
|
||||||
|
19
yarn.lock
19
yarn.lock
@ -1285,6 +1285,13 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.46.tgz#12161db48a775e8c69c1cfff2be545610381056f"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.46.tgz#12161db48a775e8c69c1cfff2be545610381056f"
|
||||||
integrity sha512-PfnRbk836fFs9T9QnZh0G1k9oC6YXCqIK3LX6vU/6oiXtEBSFCiJFj6UnLZtqIIHTsgMn8Dojq3yhmpwY7QWcw==
|
integrity sha512-PfnRbk836fFs9T9QnZh0G1k9oC6YXCqIK3LX6vU/6oiXtEBSFCiJFj6UnLZtqIIHTsgMn8Dojq3yhmpwY7QWcw==
|
||||||
|
|
||||||
|
"@types/p-queue@^3.2.1":
|
||||||
|
version "3.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/p-queue/-/p-queue-3.2.1.tgz#614957d9ed05cf6e02d08ed8f09041c4d100ef70"
|
||||||
|
integrity sha512-tgAdn5zEs05NuHzOyRM34cMO0rczStphR/kLo/ZJwwwJ5S2+QVxwA6gST3vDHWPB1oDfUuT6wOouhJvJkBCA0w==
|
||||||
|
dependencies:
|
||||||
|
p-queue "*"
|
||||||
|
|
||||||
"@types/prop-types@*":
|
"@types/prop-types@*":
|
||||||
version "15.7.1"
|
version "15.7.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.1.tgz#f1a11e7babb0c3cad68100be381d1e064c68f1f6"
|
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.1.tgz#f1a11e7babb0c3cad68100be381d1e064c68f1f6"
|
||||||
@ -4638,6 +4645,11 @@ etag@~1.8.1:
|
|||||||
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
||||||
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
|
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
|
||||||
|
|
||||||
|
eventemitter3@^3.1.0:
|
||||||
|
version "3.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7"
|
||||||
|
integrity sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==
|
||||||
|
|
||||||
events@^3.0.0:
|
events@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/events/-/events-3.0.0.tgz#9a0a0dfaf62893d92b875b8f2698ca4114973e88"
|
resolved "https://registry.yarnpkg.com/events/-/events-3.0.0.tgz#9a0a0dfaf62893d92b875b8f2698ca4114973e88"
|
||||||
@ -8184,6 +8196,13 @@ p-pipe@^1.2.0:
|
|||||||
resolved "https://registry.yarnpkg.com/p-pipe/-/p-pipe-1.2.0.tgz#4b1a11399a11520a67790ee5a0c1d5881d6befe9"
|
resolved "https://registry.yarnpkg.com/p-pipe/-/p-pipe-1.2.0.tgz#4b1a11399a11520a67790ee5a0c1d5881d6befe9"
|
||||||
integrity sha1-SxoROZoRUgpneQ7loMHViB1r7+k=
|
integrity sha1-SxoROZoRUgpneQ7loMHViB1r7+k=
|
||||||
|
|
||||||
|
p-queue@*, p-queue@^5.0.0:
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/p-queue/-/p-queue-5.0.0.tgz#80f1741d5e78a6fa72fce889406481baa5617a3c"
|
||||||
|
integrity sha512-6QfeouDf236N+MAxHch0CVIy8o/KBnmhttKjxZoOkUlzqU+u9rZgEyXH3OdckhTgawbqf5rpzmyR+07+Lv0+zg==
|
||||||
|
dependencies:
|
||||||
|
eventemitter3 "^3.1.0"
|
||||||
|
|
||||||
p-reduce@^1.0.0:
|
p-reduce@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa"
|
resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user