Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
110ca7ae
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
110ca7ae
编写于
9月 04, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt: ipc use maps
上级
f7de095e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
32 deletion
+30
-32
src/vs/base/parts/ipc/node/ipc.ts
src/vs/base/parts/ipc/node/ipc.ts
+30
-32
未找到文件。
src/vs/base/parts/ipc/node/ipc.ts
浏览文件 @
110ca7ae
...
...
@@ -151,8 +151,8 @@ function deserialize(buffer: Buffer): { header: any, body: any } {
export
class
ChannelServer
implements
IChannelServer
,
IDisposable
{
private
channels
:
{
[
name
:
string
]:
IChannel
}
=
Object
.
create
(
null
);
private
activeRequests
:
{
[
id
:
number
]:
IDisposable
;
}
=
Object
.
create
(
null
);
private
channels
=
new
Map
<
string
,
IChannel
>
(
);
private
activeRequests
=
new
Map
<
number
,
IDisposable
>
(
);
private
protocolListener
:
IDisposable
;
constructor
(
private
protocol
:
IMessagePassingProtocol
)
{
...
...
@@ -161,7 +161,7 @@ export class ChannelServer implements IChannelServer, IDisposable {
}
registerChannel
(
channelName
:
string
,
channel
:
IChannel
):
void
{
this
.
channels
[
channelName
]
=
channel
;
this
.
channels
.
set
(
channelName
,
channel
)
;
}
private
sendResponse
(
response
:
IRawResponse
):
void
{
...
...
@@ -202,7 +202,7 @@ export class ChannelServer implements IChannelServer, IDisposable {
}
private
onPromise
(
request
:
IRawPromiseRequest
):
void
{
const
channel
=
this
.
channels
[
request
.
channelName
]
;
const
channel
=
this
.
channels
.
get
(
request
.
channelName
)
;
let
promise
:
Promise
;
try
{
...
...
@@ -215,7 +215,7 @@ export class ChannelServer implements IChannelServer, IDisposable {
const
requestPromise
=
promise
.
then
(
data
=>
{
this
.
sendResponse
(
<
IRawResponse
>
{
id
,
data
,
type
:
ResponseType
.
PromiseSuccess
});
delete
this
.
activeRequests
[
request
.
id
]
;
this
.
activeRequests
.
delete
(
request
.
id
)
;
},
data
=>
{
if
(
data
instanceof
Error
)
{
this
.
sendResponse
(
<
IRawResponse
>
{
...
...
@@ -229,40 +229,36 @@ export class ChannelServer implements IChannelServer, IDisposable {
this
.
sendResponse
(
<
IRawResponse
>
{
id
,
data
,
type
:
ResponseType
.
PromiseErrorObj
});
}
delete
this
.
activeRequests
[
request
.
id
]
;
this
.
activeRequests
.
delete
(
request
.
id
)
;
});
this
.
activeRequests
[
request
.
id
]
=
toDisposable
(()
=>
requestPromise
.
cancel
(
));
this
.
activeRequests
.
set
(
request
.
id
,
toDisposable
(()
=>
requestPromise
.
cancel
()
));
}
private
onEventListen
(
request
:
IRawEventListenRequest
):
void
{
const
channel
=
this
.
channels
[
request
.
channelName
]
;
const
channel
=
this
.
channels
.
get
(
request
.
channelName
)
;
const
id
=
request
.
id
;
const
event
=
channel
.
listen
(
request
.
name
,
request
.
arg
);
const
disposable
=
event
(
data
=>
this
.
sendResponse
(
<
IRawResponse
>
{
id
,
data
,
type
:
ResponseType
.
EventFire
}));
this
.
activeRequests
[
request
.
id
]
=
disposable
;
this
.
activeRequests
.
set
(
request
.
id
,
disposable
)
;
}
private
disposeActiveRequest
(
request
:
IRawRequest
):
void
{
const
disposable
=
this
.
activeRequests
[
request
.
id
]
;
const
disposable
=
this
.
activeRequests
.
get
(
request
.
id
)
;
if
(
disposable
)
{
disposable
.
dispose
();
delete
this
.
activeRequests
[
request
.
id
]
;
this
.
activeRequests
.
delete
(
request
.
id
)
;
}
}
public
dispose
():
void
{
this
.
protocolListener
.
dispose
();
this
.
protocolListener
=
null
;
Object
.
keys
(
this
.
activeRequests
).
forEach
(
id
=>
{
this
.
activeRequests
[
<
any
>
id
].
dispose
();
});
this
.
activeRequests
=
null
;
this
.
activeRequests
.
forEach
(
d
=>
d
.
dispose
());
this
.
activeRequests
.
clear
();
}
}
...
...
@@ -270,7 +266,7 @@ export class ChannelClient implements IChannelClient, IDisposable {
private
state
:
State
=
State
.
Uninitialized
;
private
activeRequests
=
new
Set
<
IDisposable
>
();
private
handlers
:
{
[
id
:
number
]:
IHandler
;
}
=
Object
.
create
(
null
);
private
handlers
=
new
Map
<
number
,
IHandler
>
(
);
private
lastRequestId
:
number
=
0
;
private
protocolListener
:
IDisposable
;
...
...
@@ -297,7 +293,7 @@ export class ChannelClient implements IChannelClient, IDisposable {
const
id
=
request
.
id
;
return
new
TPromise
((
c
,
e
)
=>
{
this
.
handlers
[
id
]
=
response
=>
{
const
handler
:
IHandler
=
response
=>
{
switch
(
response
.
type
)
{
case
ResponseType
.
PromiseSuccess
:
delete
this
.
handlers
[
id
];
...
...
@@ -319,6 +315,7 @@ export class ChannelClient implements IChannelClient, IDisposable {
}
};
this
.
handlers
.
set
(
id
,
handler
);
this
.
sendRequest
(
request
);
},
()
=>
this
.
sendRequest
({
id
,
type
:
RequestType
.
PromiseCancel
}));
});
...
...
@@ -357,7 +354,9 @@ export class ChannelClient implements IChannelClient, IDisposable {
}
});
this
.
handlers
[
id
]
=
(
response
:
IRawEventFireResponse
)
=>
emitter
.
fire
(
response
.
data
);
const
handler
:
IHandler
=
(
res
:
IRawEventFireResponse
)
=>
emitter
.
fire
(
res
.
data
);
this
.
handlers
.
set
(
id
,
handler
);
return
emitter
.
event
;
}
...
...
@@ -404,7 +403,7 @@ export class ChannelClient implements IChannelClient, IDisposable {
return
;
}
const
handler
=
this
.
handlers
[
response
.
id
]
;
const
handler
=
this
.
handlers
.
get
(
response
.
id
)
;
if
(
handler
)
{
handler
(
response
);
...
...
@@ -442,8 +441,8 @@ export interface ClientConnectionEvent {
*/
export
class
IPCServer
implements
IChannelServer
,
IRoutingChannelClient
,
IDisposable
{
private
channels
:
{
[
name
:
string
]:
IChannel
}
=
Object
.
create
(
null
);
private
channelClients
:
{
[
id
:
string
]:
ChannelClient
;
}
=
Object
.
create
(
null
);
private
channels
=
new
Map
<
string
,
IChannel
>
(
);
private
channelClients
=
new
Map
<
string
,
ChannelClient
>
(
);
private
onClientAdded
=
new
Emitter
<
string
>
();
constructor
(
onDidClientConnect
:
Event
<
ClientConnectionEvent
>
)
{
...
...
@@ -454,17 +453,16 @@ export class IPCServer implements IChannelServer, IRoutingChannelClient, IDispos
const
channelServer
=
new
ChannelServer
(
protocol
);
const
channelClient
=
new
ChannelClient
(
protocol
);
Object
.
keys
(
this
.
channels
)
.
forEach
(
name
=>
channelServer
.
registerChannel
(
name
,
this
.
channels
[
name
]));
this
.
channels
.
forEach
((
channel
,
name
)
=>
channelServer
.
registerChannel
(
name
,
channel
));
const
id
=
rawId
.
toString
();
this
.
channelClients
[
id
]
=
channelClient
;
this
.
channelClients
.
set
(
id
,
channelClient
)
;
this
.
onClientAdded
.
fire
(
id
);
onDidClientDisconnect
(()
=>
{
channelServer
.
dispose
();
channelClient
.
dispose
();
delete
this
.
channelClients
[
id
]
;
this
.
channelClients
.
delete
(
id
)
;
});
});
});
...
...
@@ -493,7 +491,7 @@ export class IPCServer implements IChannelServer, IRoutingChannelClient, IDispos
}
registerChannel
(
channelName
:
string
,
channel
:
IChannel
):
void
{
this
.
channels
[
channelName
]
=
channel
;
this
.
channels
.
set
(
channelName
,
channel
)
;
}
private
getClient
(
clientId
:
string
):
TPromise
<
IChannelClient
>
{
...
...
@@ -501,7 +499,7 @@ export class IPCServer implements IChannelServer, IRoutingChannelClient, IDispos
return
TPromise
.
wrapError
(
new
Error
(
'
Client id should be provided
'
));
}
const
client
=
this
.
channelClients
[
clientId
]
;
const
client
=
this
.
channelClients
.
get
(
clientId
)
;
if
(
client
)
{
return
TPromise
.
as
(
client
);
...
...
@@ -509,13 +507,13 @@ export class IPCServer implements IChannelServer, IRoutingChannelClient, IDispos
return
new
TPromise
<
IChannelClient
>
(
c
=>
{
const
onClient
=
once
(
filterEvent
(
this
.
onClientAdded
.
event
,
id
=>
id
===
clientId
));
onClient
(()
=>
c
(
this
.
channelClients
[
clientId
]
));
onClient
(()
=>
c
(
this
.
channelClients
.
get
(
clientId
)
));
});
}
dispose
():
void
{
this
.
channels
=
Object
.
create
(
null
);
this
.
channelClients
=
Object
.
create
(
null
);
this
.
channels
.
clear
(
);
this
.
channelClients
.
clear
(
);
this
.
onClientAdded
.
dispose
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录