CodeRunner

Runs code for environments that run programs, injected by the host.

@internote/canvas-sdkInterface
On this page
import { CodeRunner } from '@internote/canvas-sdk';

The shape is an event stream rather than a result: runs are long relative to a frame, output interleaves stdout and stderr, and the reader can stop one mid-flight.

#Fields

availabilityRequired
Returns whether running is possible right now. A method rather than a value, since a host answers live as sign-in settles.
CodeRunAvailability
notifyUnavailable
Called when the reader presses Run while running is unavailable. The button stays pressable on purpose, since a disabled control cannot explain itself, and this is where the host raises its own prompt. Absent means the press is ignored.
void
runRequired
Runs a program, calling onEvent for each frame. Resolves when the stream is fully consumed or aborted, and rejects on transport failure.
Promise<void>

#Example

const runner = ctx.runner;
if (!runner || !runner.availability().ok) return;
await runner.run(
    { identity: ctx.identity, language: 'python', code, fileName: 'exercise.py', signal },
    (event) => { if (event.type === 'stdout') append(event.text); },
);

Declared in packages/canvas-sdk/src/runner/index.ts:85.

Last updated