Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1b2aab7d
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,发现更多精彩内容 >>
提交
1b2aab7d
编写于
9月 11, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove remaining users of cancel and cancel-callback, #56137
上级
677b68da
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
60 addition
and
146 deletion
+60
-146
src/vs/base/common/async.ts
src/vs/base/common/async.ts
+9
-33
src/vs/base/common/worker/simpleWorker.ts
src/vs/base/common/worker/simpleWorker.ts
+1
-3
src/vs/base/parts/tree/browser/treeModel.ts
src/vs/base/parts/tree/browser/treeModel.ts
+2
-4
src/vs/base/test/common/async.test.ts
src/vs/base/test/common/async.test.ts
+42
-99
src/vs/editor/common/services/editorWorkerServiceImpl.ts
src/vs/editor/common/services/editorWorkerServiceImpl.ts
+4
-4
src/vs/editor/common/services/webWorker.ts
src/vs/editor/common/services/webWorker.ts
+2
-3
未找到文件。
src/vs/base/common/async.ts
浏览文件 @
1b2aab7d
...
...
@@ -129,8 +129,6 @@ export class Throttler {
this
.
queuedPromise
=
new
TPromise
(
c
=>
{
this
.
activePromise
.
then
(
onComplete
,
onComplete
).
then
(
c
);
},
()
=>
{
this
.
activePromise
.
cancel
();
});
}
...
...
@@ -149,8 +147,6 @@ export class Throttler {
this
.
activePromise
=
null
;
e
(
err
);
});
},
()
=>
{
this
.
activePromise
.
cancel
();
});
}
}
...
...
@@ -192,13 +188,14 @@ export class Delayer<T> {
private
timeout
:
number
;
private
completionPromise
:
TPromise
;
private
onSuccess
:
ValueCallback
;
private
doResolve
:
ValueCallback
;
private
doReject
:
(
err
:
any
)
=>
void
;
private
task
:
ITask
<
T
|
TPromise
<
T
>>
;
constructor
(
public
defaultDelay
:
number
)
{
this
.
timeout
=
null
;
this
.
completionPromise
=
null
;
this
.
onSuccess
=
null
;
this
.
doResolve
=
null
;
this
.
task
=
null
;
}
...
...
@@ -207,13 +204,12 @@ export class Delayer<T> {
this
.
cancelTimeout
();
if
(
!
this
.
completionPromise
)
{
this
.
completionPromise
=
new
TPromise
((
c
)
=>
{
this
.
onSuccess
=
c
;
},
()
=>
{
// no-op
this
.
completionPromise
=
new
TPromise
((
c
,
e
)
=>
{
this
.
doResolve
=
c
;
this
.
doReject
=
e
;
}).
then
(()
=>
{
this
.
completionPromise
=
null
;
this
.
onSuccess
=
null
;
this
.
doResolve
=
null
;
const
task
=
this
.
task
;
this
.
task
=
null
;
...
...
@@ -223,7 +219,7 @@ export class Delayer<T> {
this
.
timeout
=
setTimeout
(()
=>
{
this
.
timeout
=
null
;
this
.
onSuccess
(
null
);
this
.
doResolve
(
null
);
},
delay
);
return
this
.
completionPromise
;
...
...
@@ -237,7 +233,7 @@ export class Delayer<T> {
this
.
cancelTimeout
();
if
(
this
.
completionPromise
)
{
this
.
completionPromise
.
cancel
(
);
this
.
doReject
(
errors
.
canceled
()
);
this
.
completionPromise
=
null
;
}
}
...
...
@@ -302,26 +298,6 @@ export class Barrier {
}
}
export
class
ShallowCancelThenPromise
<
T
>
extends
TPromise
<
T
>
{
constructor
(
outer
:
TPromise
<
T
>
)
{
let
completeCallback
:
ValueCallback
,
errorCallback
:
ErrorCallback
;
super
((
c
,
e
)
=>
{
completeCallback
=
c
;
errorCallback
=
e
;
},
()
=>
{
// cancel this promise but not the
// outer promise
errorCallback
(
errors
.
canceled
());
});
outer
.
then
(
completeCallback
,
errorCallback
);
}
}
/**
* Replacement for `WinJS.TPromise.timeout`.
*/
...
...
src/vs/base/common/worker/simpleWorker.ts
浏览文件 @
1b2aab7d
...
...
@@ -7,7 +7,6 @@
import
{
transformErrorForSerialization
}
from
'
vs/base/common/errors
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ErrorCallback
,
TPromise
,
ValueCallback
}
from
'
vs/base/common/winjs.base
'
;
import
{
ShallowCancelThenPromise
}
from
'
vs/base/common/async
'
;
import
{
isWeb
}
from
'
vs/base/common/platform
'
;
const
INITIALIZE
=
'
$initialize
'
;
...
...
@@ -266,8 +265,7 @@ export class SimpleWorkerClient<T> extends Disposable {
}
public
getProxyObject
():
TPromise
<
T
>
{
// Do not allow chaining promises to cancel the proxy creation
return
new
ShallowCancelThenPromise
(
this
.
_lazyProxy
);
return
this
.
_lazyProxy
;
}
private
_request
(
method
:
string
,
args
:
any
[]):
TPromise
<
any
>
{
...
...
src/vs/base/parts/tree/browser/treeModel.ts
浏览文件 @
1b2aab7d
...
...
@@ -84,13 +84,11 @@ export class Lock {
var
lock
=
this
.
getLock
(
item
);
if
(
lock
)
{
var
unbindListener
:
IDisposable
;
return
new
WinJS
.
TPromise
((
c
,
e
)
=>
{
unbindListener
=
once
(
lock
.
onDispose
)(()
=>
{
once
(
lock
.
onDispose
)(()
=>
{
return
this
.
run
(
item
,
fn
).
then
(
c
,
e
);
});
}
,
()
=>
{
unbindListener
.
dispose
();
}
);
});
}
var
result
:
WinJS
.
Promise
;
...
...
src/vs/base/test/common/async.test.ts
浏览文件 @
1b2aab7d
...
...
@@ -41,16 +41,16 @@ suite('Async', () => {
return
result
;
});
test
(
'
Cancel callback behaviour
'
,
async
function
()
{
let
withCancelCallback
=
new
T
Promise
(()
=>
{
},
()
=>
{
});
let
withoutCancelCallback
=
new
TPromise
(()
=>
{
});
//
test('Cancel callback behaviour', async function () {
// let withCancelCallback = new WinJs
Promise(() => { }, () => { });
//
let withoutCancelCallback = new TPromise(() => { });
withCancelCallback
.
cancel
();
withoutCancelCallback
.
cancel
();
//
withCancelCallback.cancel();
// (withoutCancelCallback as WinJsPromise)
.cancel();
await
withCancelCallback
.
then
(
undefined
,
err
=>
{
assert
.
ok
(
isPromiseCanceledError
(
err
));
});
await
withoutCancelCallback
.
then
(
undefined
,
err
=>
{
assert
.
ok
(
isPromiseCanceledError
(
err
));
});
});
//
await withCancelCallback.then(undefined, err => { assert.ok(isPromiseCanceledError(err)); });
//
await withoutCancelCallback.then(undefined, err => { assert.ok(isPromiseCanceledError(err)); });
//
});
// Cancelling a sync cancelable promise will fire the cancelled token.
// Also, every `then` callback runs in another execution frame.
...
...
@@ -97,49 +97,49 @@ suite('Async', () => {
return
promise
.
then
(()
=>
assert
.
deepEqual
(
order
,
[
'
in callback
'
,
'
afterCreate
'
,
'
cancelled
'
,
'
afterCancel
'
,
'
finally
'
]));
});
// Cancelling a sync tpromise will NOT cancel the promise, since it has resolved already.
// Every `then` callback runs sync in the same execution frame, thus `finally` executes
// before `afterCancel`.
test
(
'
TPromise execution order (sync)
'
,
function
()
{
const
order
=
[];
let
promise
=
new
T
Promise
(
resolve
=>
{
order
.
push
(
'
in executor
'
);
resolve
(
1234
);
},
()
=>
order
.
push
(
'
cancelled
'
));
//
//
Cancelling a sync tpromise will NOT cancel the promise, since it has resolved already.
//
//
Every `then` callback runs sync in the same execution frame, thus `finally` executes
//
//
before `afterCancel`.
//
test('TPromise execution order (sync)', function () {
//
const order = [];
// let promise = new WinJs
Promise(resolve => {
//
order.push('in executor');
//
resolve(1234);
//
}, () => order.push('cancelled'));
order
.
push
(
'
afterCreate
'
);
//
order.push('afterCreate');
promise
=
promise
.
then
(
null
,
err
=>
null
)
.
then
(()
=>
order
.
push
(
'
finally
'
));
//
promise = promise
//
.then(null, err => null)
//
.then(() => order.push('finally'));
promise
.
cancel
();
order
.
push
(
'
afterCancel
'
);
//
promise.cancel();
//
order.push('afterCancel');
return
promise
.
then
(()
=>
assert
.
deepEqual
(
order
,
[
'
in executor
'
,
'
afterCreate
'
,
'
finally
'
,
'
afterCancel
'
]));
});
//
return promise.then(() => assert.deepEqual(order, ['in executor', 'afterCreate', 'finally', 'afterCancel']));
//
});
// Cancelling an async tpromise will cancel the promise.
// Every `then` callback runs sync on the same execution frame as the `cancel` call,
// so finally still executes before `afterCancel`.
test
(
'
TPromise execution order (async)
'
,
function
()
{
const
order
=
[];
let
promise
=
new
T
Promise
(
resolve
=>
{
order
.
push
(
'
in executor
'
);
setTimeout
(()
=>
resolve
(
1234
));
},
()
=>
order
.
push
(
'
cancelled
'
));
//
//
Cancelling an async tpromise will cancel the promise.
//
//
Every `then` callback runs sync on the same execution frame as the `cancel` call,
//
//
so finally still executes before `afterCancel`.
//
test('TPromise execution order (async)', function () {
//
const order = [];
// let promise = new WinJs
Promise(resolve => {
//
order.push('in executor');
//
setTimeout(() => resolve(1234));
//
}, () => order.push('cancelled'));
order
.
push
(
'
afterCreate
'
);
//
order.push('afterCreate');
promise
=
promise
.
then
(
null
,
err
=>
null
)
.
then
(()
=>
order
.
push
(
'
finally
'
));
//
promise = promise
//
.then(null, err => null)
//
.then(() => order.push('finally'));
promise
.
cancel
();
order
.
push
(
'
afterCancel
'
);
//
promise.cancel();
//
order.push('afterCancel');
return
promise
.
then
(()
=>
assert
.
deepEqual
(
order
,
[
'
in executor
'
,
'
afterCreate
'
,
'
cancelled
'
,
'
finally
'
,
'
afterCancel
'
]));
});
//
return promise.then(() => assert.deepEqual(order, ['in executor', 'afterCreate', 'cancelled', 'finally', 'afterCancel']));
//
});
test
(
'
cancelablePromise - get inner result
'
,
async
function
()
{
let
promise
=
async
.
createCancelablePromise
(
token
=>
{
...
...
@@ -190,63 +190,6 @@ suite('Async', () => {
});
});
test
(
'
Throttler - cancel should not cancel other promises
'
,
function
()
{
let
count
=
0
;
let
factory
=
()
=>
TPromise
.
wrap
(
async
.
timeout
(
0
)).
then
(()
=>
++
count
);
let
throttler
=
new
async
.
Throttler
();
let
p1
:
TPromise
;
const
p
=
TPromise
.
join
([
p1
=
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
(
false
,
'
should not be here, 1
'
);
},
()
=>
{
assert
(
true
,
'
yes, it was cancelled
'
);
}),
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
1
);
},
()
=>
{
assert
(
false
,
'
should not be here, 2
'
);
}),
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
1
);
},
()
=>
{
assert
(
false
,
'
should not be here, 3
'
);
}),
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
1
);
},
()
=>
{
assert
(
false
,
'
should not be here, 4
'
);
})
]);
p1
.
cancel
();
return
p
;
});
test
(
'
Throttler - cancel the first queued promise should not cancel other promises
'
,
function
()
{
let
count
=
0
;
let
factory
=
()
=>
TPromise
.
wrap
(
async
.
timeout
(
0
)).
then
(()
=>
++
count
);
let
throttler
=
new
async
.
Throttler
();
let
p2
:
TPromise
;
const
p
=
TPromise
.
join
([
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
1
);
},
()
=>
{
assert
(
false
,
'
should not be here, 1
'
);
}),
p2
=
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
(
false
,
'
should not be here, 2
'
);
},
()
=>
{
assert
(
true
,
'
yes, it was cancelled
'
);
}),
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
2
);
},
()
=>
{
assert
(
false
,
'
should not be here, 3
'
);
}),
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
2
);
},
()
=>
{
assert
(
false
,
'
should not be here, 4
'
);
})
]);
p2
.
cancel
();
return
p
;
});
test
(
'
Throttler - cancel in the middle should not cancel other promises
'
,
function
()
{
let
count
=
0
;
let
factory
=
()
=>
TPromise
.
wrap
(
async
.
timeout
(
0
)).
then
(()
=>
++
count
);
let
throttler
=
new
async
.
Throttler
();
let
p3
:
TPromise
;
const
p
=
TPromise
.
join
([
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
1
);
},
()
=>
{
assert
(
false
,
'
should not be here, 1
'
);
}),
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
2
);
},
()
=>
{
assert
(
false
,
'
should not be here, 2
'
);
}),
p3
=
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
(
false
,
'
should not be here, 3
'
);
},
()
=>
{
assert
(
true
,
'
yes, it was cancelled
'
);
}),
throttler
.
queue
(
factory
).
then
((
result
)
=>
{
assert
.
equal
(
result
,
2
);
},
()
=>
{
assert
(
false
,
'
should not be here, 4
'
);
})
]);
p3
.
cancel
();
return
p
;
});
test
(
'
Throttler - last factory should be the one getting called
'
,
function
()
{
let
factoryFactory
=
(
n
:
number
)
=>
()
=>
{
return
TPromise
.
wrap
(
async
.
timeout
(
0
)).
then
(()
=>
n
);
...
...
src/vs/editor/common/services/editorWorkerServiceImpl.ts
浏览文件 @
1b2aab7d
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
IntervalTimer
,
ShallowCancelThenPromise
}
from
'
vs/base/common/async
'
;
import
{
IntervalTimer
}
from
'
vs/base/common/async
'
;
import
{
Disposable
,
IDisposable
,
dispose
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -321,7 +321,7 @@ class SynchronousWorkerClient<T extends IDisposable> implements IWorkerClient<T>
}
public
getProxyObject
():
TPromise
<
T
>
{
return
new
ShallowCancelThenPromise
(
this
.
_proxyObj
)
;
return
this
.
_proxyObj
;
}
}
...
...
@@ -356,11 +356,11 @@ export class EditorWorkerClient extends Disposable {
}
protected
_getProxy
():
TPromise
<
EditorSimpleWorkerImpl
>
{
return
new
ShallowCancelThenPromise
(
this
.
_getOrCreateWorker
().
getProxyObject
().
then
(
null
,
(
err
)
=>
{
return
this
.
_getOrCreateWorker
().
getProxyObject
().
then
(
null
,
(
err
)
=>
{
logOnceWebWorkerWarning
(
err
);
this
.
_worker
=
new
SynchronousWorkerClient
(
new
EditorSimpleWorkerImpl
(
null
));
return
this
.
_getOrCreateWorker
().
getProxyObject
();
})
)
;
});
}
private
_getOrCreateModelManager
(
proxy
:
EditorSimpleWorkerImpl
):
EditorModelManager
{
...
...
src/vs/editor/common/services/webWorker.ts
浏览文件 @
1b2aab7d
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
ShallowCancelThenPromise
}
from
'
vs/base/common/async
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
...
...
@@ -68,7 +67,7 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
private
_getForeignProxy
():
TPromise
<
T
>
{
if
(
!
this
.
_foreignProxy
)
{
this
.
_foreignProxy
=
new
ShallowCancelThenPromise
(
this
.
_getProxy
().
then
((
proxy
)
=>
{
this
.
_foreignProxy
=
this
.
_getProxy
().
then
((
proxy
)
=>
{
return
proxy
.
loadForeignModule
(
this
.
_foreignModuleId
,
this
.
_foreignModuleCreateData
).
then
((
foreignMethods
)
=>
{
this
.
_foreignModuleId
=
null
;
this
.
_foreignModuleCreateData
=
null
;
...
...
@@ -91,7 +90,7 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
return
foreignProxy
;
});
})
)
;
});
}
return
this
.
_foreignProxy
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录