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
6d3565dc
Commit
6d3565dc
authored
7 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
mol-comp prototype tweak
parent
562cb9ac
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mol-comp/util.ts
+22
-4
22 additions, 4 deletions
src/mol-comp/util.ts
with
22 additions
and
4 deletions
src/mol-comp/util.ts
+
22
−
4
View file @
6d3565dc
type
ExecutionContext
=
{
getRuntimeCtx
(
c
:
Computation
<
any
>
):
RuntimeContext
,
subscribe
(
o
:
(
p
:
string
,
compId
:
number
)
=>
void
):
void
}
type
ExecutionContext
=
{
run
<
T
>
(
c
:
Computation
<
T
>
,
params
?:
{
updateRateMs
:
number
}):
Promise
<
T
>
,
subscribe
(
o
:
(
p
:
string
,
compId
:
number
)
=>
void
):
void
}
namespace
ExecutionContext
{
// export interface Synchronous extends ExecutionContext {
// run<T>(c: Computation<T>, params?: { updateRateMs: number }): Promise<T>,
// }
type
RuntimeContext
=
{
yield
(
name
:
string
):
Promise
<
void
>
|
void
,
createChildContext
():
RuntimeContext
}
// export interface Observable extends ExecutionContext {
// run<T>(c: Computation<T>, params?: { updateRateMs: number }): Promise<T>,
// }
export
const
Sync
:
ExecutionContext
=
0
as
any
;
}
interface
RuntimeContext
extends
ExecutionContext
{
yield
(
name
:
string
):
Promise
<
void
>
|
void
}
// if no context is specified, use the synchronous one.
type
Computation
<
T
>
=
{
(
ctx
?:
RuntimeContext
):
Promise
<
T
>
,
_id
:
number
}
type
Computation
<
T
>
=
{
(
ctx
?:
RuntimeContext
):
Promise
<
T
>
,
_id
:
number
}
function
create
<
T
>
(
c
:
(
ctx
:
RuntimeContext
)
=>
Promise
<
T
>
):
Computation
<
T
>
{
return
0
as
any
;
}
function
create
<
T
>
(
c
:
(
ctx
:
RuntimeContext
)
=>
Promise
<
T
>
):
Computation
<
T
>
{
return
0
as
any
;
}
function
constant
<
T
>
(
c
:
T
)
{
return
create
(
async
ctx
=>
c
);
}
type
MultistepFn
<
P
,
T
>
=
(
params
:
P
,
step
:
(
s
:
number
)
=>
Promise
<
void
>
|
void
,
ctx
:
RuntimeContext
)
=>
Promise
<
T
>
type
MultistepFn
<
P
,
T
>
=
(
params
:
P
,
step
:
(
s
:
number
)
=>
Promise
<
void
>
|
void
,
ctx
:
RuntimeContext
)
=>
Promise
<
T
>
type
ComputationProvider
<
P
,
T
>
=
(
params
:
P
)
=>
Computation
<
T
>
type
ComputationProvider
<
P
,
T
>
=
(
params
:
P
)
=>
Computation
<
T
>
...
@@ -40,7 +58,7 @@ function readLines(str: string): Computation<string[]> {
...
@@ -40,7 +58,7 @@ function readLines(str: string): Computation<string[]> {
const
prependHiToLines
=
MultistepComputation
(
'
Hi prepend
'
,
[
'
Parse input
'
,
'
Prepend Hi
'
],
async
(
p
:
string
,
step
,
ctx
)
=>
{
const
prependHiToLines
=
MultistepComputation
(
'
Hi prepend
'
,
[
'
Parse input
'
,
'
Prepend Hi
'
],
async
(
p
:
string
,
step
,
ctx
)
=>
{
await
step
(
0
);
await
step
(
0
);
const
lines
=
await
readLines
(
p
)
(
ctx
);
const
lines
=
await
ctx
.
run
(
readLines
(
p
));
await
step
(
1
);
await
step
(
1
);
const
ret
=
lines
.
map
(
l
=>
'
Hi
'
+
l
);
const
ret
=
lines
.
map
(
l
=>
'
Hi
'
+
l
);
return
ret
;
return
ret
;
...
@@ -48,6 +66,6 @@ const prependHiToLines = MultistepComputation('Hi prepend', ['Parse input', 'Pre
...
@@ -48,6 +66,6 @@ const prependHiToLines = MultistepComputation('Hi prepend', ['Parse input', 'Pre
(
async
function
()
{
(
async
function
()
{
const
r
=
await
prependHiToLines
(
'
1
\n
2
'
)
(
);
const
r
=
await
ExecutionContext
.
Sync
.
run
(
prependHiToLines
(
'
1
\n
2
'
)
,
{
updateRateMs
:
150
}
);
console
.
log
(
r
)
console
.
log
(
r
)
}())
}())
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