|
1 | 1 | import { Deferred } from '@opensumi/ide-core-common'; |
2 | 2 |
|
3 | 3 | import { METHOD_NOT_REGISTERED } from '../constants'; |
4 | | -import { ProxyLegacy } from '../proxy'; |
5 | | -import { ServiceRunner } from '../proxy/runner'; |
6 | | -import { ProxySumi } from '../proxy/sumi'; |
7 | | -import { TSumiProtocol } from '../rpc'; |
8 | | -import { ProtocolRepository } from '../rpc/protocol-repository'; |
| 4 | +import { ServiceRunner, Invoker } from '../proxy'; |
| 5 | +import { TSumiProtocol, ProtocolRepository } from '../rpc'; |
9 | 6 | import { IBench, ILogger, RPCServiceMethod, ServiceType } from '../types'; |
10 | 7 | import { getMethodName } from '../utils'; |
11 | 8 | import { WSChannel } from '../ws-channel'; |
12 | 9 |
|
13 | 10 | const safeProcess: { pid: string } = typeof process === 'undefined' ? { pid: 'mock' } : (process as any); |
14 | 11 |
|
15 | | -const defaultReservedWordSet = new Set(['then']); |
16 | | - |
17 | | -class Invoker { |
18 | | - legacyProxy: ProxyLegacy; |
19 | | - sumiProxy: ProxySumi; |
20 | | - |
21 | | - private legacyInvokeProxy: any; |
22 | | - private sumiInvokeProxy: any; |
23 | | - |
24 | | - forceUseSumi = true; |
25 | | - |
26 | | - constructor(protected repo: ProtocolRepository, public runner: ServiceRunner, channel: WSChannel, logger?: ILogger) { |
27 | | - this.legacyProxy = new ProxyLegacy(runner, logger); |
28 | | - this.legacyInvokeProxy = this.legacyProxy.getInvokeProxy(); |
29 | | - |
30 | | - this.sumiProxy = new ProxySumi(runner, logger); |
31 | | - this.sumiInvokeProxy = this.sumiProxy.getInvokeProxy(); |
32 | | - |
33 | | - this.listen(channel); |
34 | | - } |
35 | | - |
36 | | - listen(channel: WSChannel) { |
37 | | - const messageConnection = channel.createMessageConnection(); |
38 | | - this.legacyProxy.listen(messageConnection); |
39 | | - |
40 | | - const connection = channel.createConnection(); |
41 | | - connection.setProtocolRepository(this.repo); |
42 | | - this.sumiProxy.listen(connection); |
43 | | - } |
44 | | - |
45 | | - invoke(name: string, ...args: any[]) { |
46 | | - if (defaultReservedWordSet.has(name) || typeof name === 'symbol') { |
47 | | - return Promise.resolve(); |
48 | | - } |
49 | | - |
50 | | - if (this.forceUseSumi) { |
51 | | - return this.sumiInvokeProxy[name](...args); |
52 | | - } |
53 | | - |
54 | | - if (this.repo.has(name)) { |
55 | | - return this.sumiInvokeProxy[name](...args); |
56 | | - } |
57 | | - |
58 | | - return this.legacyInvokeProxy[name](...args); |
59 | | - } |
60 | | - |
61 | | - dispose() { |
62 | | - this.legacyProxy.dispose(); |
63 | | - this.sumiProxy.dispose(); |
64 | | - } |
65 | | -} |
66 | | - |
67 | 12 | export class RPCServiceCenter { |
68 | 13 | public uid: string; |
69 | 14 |
|
@@ -151,8 +96,8 @@ export class RPCServiceCenter { |
151 | 96 | } |
152 | 97 |
|
153 | 98 | // FIXME: this is an unreasonable design, if remote service only returned doubtful result, we will return an empty array. |
154 | | - // but actually we should throw an error to tell user that no remote service can handle this call. |
155 | | - // or just return `undefined`. |
| 99 | + // but actually we should throw an error to tell user that no remote service can handle this call. |
| 100 | + // or just return `undefined`. |
156 | 101 | return result.length === 1 ? result[0] : result; |
157 | 102 | } |
158 | 103 | } |
0 commit comments