Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
3a601314
Commit
3a601314
authored
5 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
mol-task: fixed subtask cancellation
parent
c5e2471f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/examples/task.ts
+4
-4
4 additions, 4 deletions
src/examples/task.ts
src/mol-task/execution/observable.ts
+8
-3
8 additions, 3 deletions
src/mol-task/execution/observable.ts
with
12 additions
and
7 deletions
src/examples/task.ts
+
4
−
4
View file @
3a601314
...
...
@@ -28,9 +28,9 @@ function messageTree(root: Progress.Node, prefix = ''): string {
function
createTask
<
T
>
(
delayMs
:
number
,
r
:
T
):
Task
<
T
>
{
return
Task
.
create
(
'
delayed value
'
+
r
,
async
ctx
=>
{
ctx
.
update
(
'
Processing delayed
...
'
+
r
,
true
);
ctx
.
update
(
`
Processing delayed
${
r
}
after
${
delayMs
}
ms`
,
true
);
await
Scheduler
.
delay
(
delayMs
);
if
(
ctx
.
shouldUpdate
)
await
ctx
.
update
({
message
:
'
hello from delayed
...
'
});
if
(
ctx
.
shouldUpdate
)
await
ctx
.
update
({
message
:
`
hello from delayed
${
r
}
${
delayMs
}
`
});
return
r
;
},
()
=>
console
.
log
(
'
On abort called
'
+
r
));
}
...
...
@@ -63,7 +63,7 @@ export function testTree() {
const
r
=
await
c1
+
await
c2
+
await
c3
;
if
(
ctx
.
shouldUpdate
)
await
ctx
.
update
({
message
:
'
Almost done...
'
});
return
r
+
1
;
});
}
,
()
=>
console
.
log
(
'
On abort O
'
)
);
}
export
type
ChunkedState
=
{
i
:
number
,
current
:
number
,
total
:
number
}
...
...
@@ -115,7 +115,7 @@ async function test() {
// const r = await Run(testTree(), abortingObserver, 250);
// console.log(r);
const
m
=
await
ms
({
i
:
10
}).
run
(
logP
);
const
m
=
await
testTree
().
run
(
abortingObserver
,
50
);
console
.
log
(
m
);
}
catch
(
e
)
{
console
.
error
(
e
);
...
...
This diff is collapsed.
Click to expand it.
src/mol-task/execution/observable.ts
+
8
−
3
View file @
3a601314
...
...
@@ -10,7 +10,7 @@ import { Progress } from './progress'
import
{
now
}
from
'
../../mol-util/now
'
;
import
{
Scheduler
}
from
'
../util/scheduler
'
import
{
UserTiming
}
from
'
../util/user-timing
'
import
{
is
Production
Mode
}
from
'
../../mol-util/debug
'
import
{
is
Debug
Mode
}
from
'
../../mol-util/debug
'
interface
ExposedTask
<
T
>
extends
Task
<
T
>
{
f
:
(
ctx
:
RuntimeContext
)
=>
Promise
<
T
>
,
...
...
@@ -101,6 +101,8 @@ async function execute<T>(task: ExposedTask<T>, ctx: ObservableRuntimeContext) {
return
ret
;
}
catch
(
e
)
{
if
(
Task
.
isAbort
(
e
))
{
ctx
.
isAborted
=
true
;
// wait for all child computations to go thru the abort phase.
if
(
ctx
.
node
.
children
.
length
>
0
)
{
await
new
Promise
(
res
=>
{
ctx
.
onChildrenFinished
=
res
;
});
...
...
@@ -109,7 +111,7 @@ async function execute<T>(task: ExposedTask<T>, ctx: ObservableRuntimeContext) {
task
.
onAbort
();
}
}
if
(
!
is
Production
Mode
)
console
.
error
(
e
);
if
(
is
Debug
Mode
)
console
.
error
(
e
);
throw
e
;
}
}
...
...
@@ -147,6 +149,8 @@ class ObservableRuntimeContext implements RuntimeContext {
isExecuting
=
true
;
lastUpdatedTime
=
0
;
isAborted
?:
boolean
;
node
:
Progress
.
Node
;
info
:
ProgressInfo
;
...
...
@@ -155,6 +159,7 @@ class ObservableRuntimeContext implements RuntimeContext {
private
checkAborted
()
{
if
(
this
.
info
.
abortToken
.
abortRequested
)
{
this
.
isAborted
=
true
;
abort
(
this
.
info
);
}
}
...
...
@@ -220,7 +225,7 @@ class ObservableRuntimeContext implements RuntimeContext {
// need to catch the error here because otherwise
// promises for running child tasks in a tree-like computation
// will get orphaned and cause "uncaught error in Promise".
return
void
0
as
any
;
if
(
this
.
isAborted
)
return
void
0
as
any
;
}
throw
e
;
}
finally
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment