stencila/designa

Execution order on Run Document

Closed this issue · 0 comments

I have noticed some instances when using remote sessions where, when pressing "Run Document", code chunks do not seem to get executed in the right order (e.g a library that is supposed to be loaded in one cell is reported as not available in later cells). Given our current execution model (i.e. one that does not use a dependency graph) we need to make sure that CodeChunks and CodeExpressions are executed in the order they appear in the document (as assumed in Jupyter and R Markdown).

Note in the below, the execution of the code chunks is triggered at the same time and it is just lucky that they get executed in the right order (most of the time).

Peek 2020-08-16 22-27

The offending lines appear to be here:

private runAll = async (
e: MouseEvent
): Promise<(CodeExpression | CodeChunk | undefined | void)[]> => {
e.preventDefault()
return this.findSession().then(() => {
return Promise.all(
this.codeNodeSelector().map(async (item) => item.execute())
)
})
}
componentDidLoad(): void {
this.codeNodeSelector().map((code) => {
// @ts-ignore
code.executeHandler = this.executeHandler
})

Instead, I think it needs to be something like:

for (const node in this.codeNodeSelector()) {
  await node.execute()
}