Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6c619202
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,发现更多精彩内容 >>
提交
6c619202
编写于
1月 27, 2020
作者:
E
Eric Amodio
提交者:
Eric Amodio
1月 27, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removes timeout/racing for now
Need to revisit how we will handle long running providers
上级
628c60d1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
109 addition
and
88 deletion
+109
-88
src/vs/workbench/contrib/timeline/common/timelineService.ts
src/vs/workbench/contrib/timeline/common/timelineService.ts
+109
-88
未找到文件。
src/vs/workbench/contrib/timeline/common/timelineService.ts
浏览文件 @
6c619202
...
...
@@ -49,26 +49,20 @@ export class TimelineService implements ITimelineService {
async
getTimeline
(
uri
:
URI
,
token
:
CancellationToken
,
sources
?:
Set
<
string
>
)
{
this
.
logService
.
trace
(
`TimelineService#getTimeline(
${
uri
.
toString
(
true
)}
)`
);
const
requests
=
new
Map
<
string
,
Promise
<
TimelineItem
[]
|
CancellationErrorWithId
<
string
>>>
()
;
const
requests
:
Promise
<
[
string
,
TimelineItem
[]]
>
[]
=
[]
;
for
(
const
provider
of
this
.
_providers
.
values
())
{
if
(
sources
&&
!
sources
.
has
(
provider
.
source
))
{
continue
;
}
requests
.
set
(
provider
.
source
,
provider
.
provideTimeline
(
uri
,
token
));
requests
.
push
(
provider
.
provideTimeline
(
uri
,
token
).
then
(
p
=>
[
provider
.
source
,
p
]
));
}
// TODO[ECA]: What should the timeout be for waiting for individual providers?
const
timelines
=
await
raceAll
(
requests
/*, 5000*/
);
const
timelines
=
await
Promise
.
all
(
requests
);
const
timeline
=
[];
for
(
const
[
source
,
items
]
of
timelines
)
{
if
(
items
instanceof
CancellationError
)
{
this
.
logService
.
trace
(
`TimelineService#getTimeline(
${
uri
.
toString
(
true
)}
) source=
${
source
}
cancelled`
);
continue
;
}
if
(
items
.
length
===
0
)
{
continue
;
}
...
...
@@ -76,6 +70,33 @@ export class TimelineService implements ITimelineService {
timeline
.
push
(...
items
.
map
(
item
=>
({
...
item
,
source
:
source
})));
}
// const requests = new Map<string, Promise<TimelineItem[] | CancellationErrorWithId<string>>>();
// for (const provider of this._providers.values()) {
// if (sources && !sources.has(provider.source)) {
// continue;
// }
// requests.set(provider.source, provider.provideTimeline(uri, token));
// }
// // TODO[ECA]: What should the timeout be for waiting for individual providers?
// const timelines = await raceAll(requests /*, 5000*/);
// const timeline = [];
// for (const [source, items] of timelines) {
// if (items instanceof CancellationError) {
// this.logService.trace(`TimelineService#getTimeline(${uri.toString(true)}) source=${source} cancelled`);
// continue;
// }
// if (items.length === 0) {
// continue;
// }
// timeline.push(...items.map(item => ({ ...item, source: source })));
// }
timeline
.
sort
((
a
,
b
)
=>
b
.
timestamp
-
a
.
timestamp
);
return
timeline
;
}
...
...
@@ -123,82 +144,82 @@ export class TimelineService implements ITimelineService {
}
}
function
*
map
<
T
,
TMapped
>
(
source
:
Iterable
<
T
>
|
IterableIterator
<
T
>
,
mapper
:
(
item
:
T
)
=>
TMapped
):
Iterable
<
TMapped
>
{
for
(
const
item
of
source
)
{
yield
mapper
(
item
);
}
}
class
CancellationError
<
TPromise
=
any
>
extends
Error
{
constructor
(
public
readonly
promise
:
TPromise
,
message
:
string
)
{
super
(
message
);
}
}
class
CancellationErrorWithId
<
T
,
TPromise
=
any
>
extends
CancellationError
<
TPromise
>
{
constructor
(
public
readonly
id
:
T
,
promise
:
TPromise
,
message
:
string
)
{
super
(
promise
,
message
);
}
}
function
raceAll
<
TPromise
>
(
promises
:
Promise
<
TPromise
>
[],
timeout
?:
number
):
Promise
<
(
TPromise
|
CancellationError
<
Promise
<
TPromise
>>
)[]
>
;
function
raceAll
<
TPromise
,
T
>
(
promises
:
Map
<
T
,
Promise
<
TPromise
>>
,
timeout
?:
number
):
Promise
<
Map
<
T
,
TPromise
|
CancellationErrorWithId
<
T
,
Promise
<
TPromise
>>>>
;
function
raceAll
<
TPromise
,
T
>
(
ids
:
Iterable
<
T
>
,
fn
:
(
id
:
T
)
=>
Promise
<
TPromise
>
,
timeout
?:
number
):
Promise
<
Map
<
T
,
TPromise
|
CancellationErrorWithId
<
T
,
Promise
<
TPromise
>>>>
;
async
function
raceAll
<
TPromise
,
T
>
(
promisesOrIds
:
Promise
<
TPromise
>
[]
|
Map
<
T
,
Promise
<
TPromise
>>
|
Iterable
<
T
>
,
timeoutOrFn
?:
number
|
((
id
:
T
)
=>
Promise
<
TPromise
>
),
timeout
?:
number
)
{
let
promises
;
if
(
timeoutOrFn
!==
undefined
&&
typeof
timeoutOrFn
!==
'
number
'
)
{
promises
=
new
Map
(
map
<
T
,
[
T
,
Promise
<
TPromise
>
]
>
(
promisesOrIds
as
Iterable
<
T
>
,
id
=>
[
id
,
timeoutOrFn
(
id
)])
);
}
else
{
timeout
=
timeoutOrFn
;
promises
=
promisesOrIds
as
Promise
<
TPromise
>
[]
|
Map
<
T
,
Promise
<
TPromise
>>
;
}
if
(
promises
instanceof
Map
)
{
return
new
Map
(
await
Promise
.
all
(
map
<
[
T
,
Promise
<
TPromise
>
],
Promise
<
[
T
,
TPromise
|
CancellationErrorWithId
<
T
,
Promise
<
TPromise
>>
]
>>
(
promises
.
entries
(),
timeout
===
undefined
?
([
id
,
promise
])
=>
promise
.
then
(
p
=>
[
id
,
p
])
:
([
id
,
promise
])
=>
Promise
.
race
([
promise
,
new
Promise
<
CancellationErrorWithId
<
T
,
Promise
<
TPromise
>>>
(
resolve
=>
setTimeout
(()
=>
resolve
(
new
CancellationErrorWithId
(
id
,
promise
,
'
TIMED OUT
'
)),
timeout
!
)
)
]).
then
(
p
=>
[
id
,
p
])
)
)
);
}
return
Promise
.
all
(
timeout
===
undefined
?
promises
:
promises
.
map
(
p
=>
Promise
.
race
([
p
,
new
Promise
<
CancellationError
<
Promise
<
TPromise
>>>
(
resolve
=>
setTimeout
(()
=>
resolve
(
new
CancellationError
(
p
,
'
TIMED OUT
'
)),
timeout
!
)
)
])
)
);
}
//
function* map<T, TMapped>(source: Iterable<T> | IterableIterator<T>, mapper: (item: T) => TMapped): Iterable<TMapped> {
//
for (const item of source) {
//
yield mapper(item);
//
}
//
}
//
class CancellationError<TPromise = any> extends Error {
//
constructor(public readonly promise: TPromise, message: string) {
//
super(message);
//
}
//
}
//
class CancellationErrorWithId<T, TPromise = any> extends CancellationError<TPromise> {
//
constructor(public readonly id: T, promise: TPromise, message: string) {
//
super(promise, message);
//
}
//
}
//
function raceAll<TPromise>(
//
promises: Promise<TPromise>[],
//
timeout?: number
//
): Promise<(TPromise | CancellationError<Promise<TPromise>>)[]>;
//
function raceAll<TPromise, T>(
//
promises: Map<T, Promise<TPromise>>,
//
timeout?: number
//
): Promise<Map<T, TPromise | CancellationErrorWithId<T, Promise<TPromise>>>>;
//
function raceAll<TPromise, T>(
//
ids: Iterable<T>,
//
fn: (id: T) => Promise<TPromise>,
//
timeout?: number
//
): Promise<Map<T, TPromise | CancellationErrorWithId<T, Promise<TPromise>>>>;
//
async function raceAll<TPromise, T>(
//
promisesOrIds: Promise<TPromise>[] | Map<T, Promise<TPromise>> | Iterable<T>,
//
timeoutOrFn?: number | ((id: T) => Promise<TPromise>),
//
timeout?: number
//
) {
//
let promises;
//
if (timeoutOrFn !== undefined && typeof timeoutOrFn !== 'number') {
//
promises = new Map(
//
map<T, [T, Promise<TPromise>]>(promisesOrIds as Iterable<T>, id => [id, timeoutOrFn(id)])
//
);
//
} else {
//
timeout = timeoutOrFn;
//
promises = promisesOrIds as Promise<TPromise>[] | Map<T, Promise<TPromise>>;
//
}
//
if (promises instanceof Map) {
//
return new Map(
//
await Promise.all(
//
map<[T, Promise<TPromise>], Promise<[T, TPromise | CancellationErrorWithId<T, Promise<TPromise>>]>>(
//
promises.entries(),
//
timeout === undefined
//
? ([id, promise]) => promise.then(p => [id, p])
//
: ([id, promise]) =>
//
Promise.race([
//
promise,
//
new Promise<CancellationErrorWithId<T, Promise<TPromise>>>(resolve =>
//
setTimeout(() => resolve(new CancellationErrorWithId(id, promise, 'TIMED OUT')), timeout!)
//
)
//
]).then(p => [id, p])
//
)
//
)
//
);
//
}
//
return Promise.all(
//
timeout === undefined
//
? promises
//
: promises.map(p =>
//
Promise.race([
//
p,
//
new Promise<CancellationError<Promise<TPromise>>>(resolve =>
//
setTimeout(() => resolve(new CancellationError(p, 'TIMED OUT')), timeout!)
//
)
//
])
//
)
//
);
//
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录