Skip to content

execute() hook for Positron can run blocks out of order  #509

Closed
@DavisVaughan

Description

@DavisVaughan

See posit-dev/positron#4231

Check out the following video. If you "run all above" and then very quickly run another code block, then the blocks have the potential to be run out of order.

broken.mov

This is due to the way this execute() hook works for Positron

execute: async (blocks: string[], _editorUri?: vscode.Uri) : Promise<void> => {
for (const block of blocks) {
let code = block;
if (language === "python" && isKnitrDocument(document, engine)) {
language = "r";
code = pythonWithReticulate(block);
}
await hooksApi()?.runtime.executeCode(language, code, false);
}
},

Note that the await happens within the loop at each iteration. That means that after the first await, we can switch away to some other code - in particular someone else could call execute() and we could execute their code before we finish executing all of the blocks that we need to run.

@lionel- and I have a patch that only performs the await on the last code block. That ensures that we can sequentially fire off all of the blocks without the potential of having someone else execute code in between two of our blocks. I'll send in a PR for this.


---
title: "Untitled"
format: html
---


```{r}
library(tidyverse)
library(phyloseq)
library(decontam)
```


```{r}
x <- 1
```

```{r}
y <- x
```

```{r}
z <- y
```

```{r}
a <- z
```


```{r}

```


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions