Table of Contents

Interface IProgramMachine

Namespace
RDCore.SDK.Runtime.Hosting
Assembly
RDCore.SDK.dll

A machine: one runtime session of a composed program (CreateMachineAsync(CancellationToken)), which runs one invocation at a time.

public interface IProgramMachine : IAsyncDisposable
Inherited Members

Remarks

Every machine of a program has a state of its own: module-level variables, Static locals, objects, open files, error state and current directory. Two machines may run at the same time, each on a thread of its own; concurrency comes from several machines, never from two invocations of one. ResetAsync(CancellationToken) returns a machine to the state it was made in, so that nothing of one invocation reaches the next.

Methods

InvokeAsync(ProgramInvocation, CancellationToken)

Runs one procedure of the program with the invocation's arguments. A procedure of a class whose VB_PredeclaredId is True runs on the class's default instance, which keeps its state between invocations; a procedure of any other class module runs on a new object of the class, initialized before it and terminated once the run has its value (ProgramInvocation). The invocation's calls, guards, factory, hooks and result calls run in the same run.

Task<ProgramInvocationResult> InvokeAsync(ProgramInvocation invocation, CancellationToken cancellationToken)

Parameters

invocation ProgramInvocation

The procedure, its arguments, and the calls, guards, factory, hooks and result calls that run with it.

cancellationToken CancellationToken

Interrupts the invocation between two instructions: the result is Interrupted. A call outside the program (a Declare or a COM object) returns before the interruption is seen.

Returns

Task<ProgramInvocationResult>

The invocation's value, as JSON: the procedure's, or that of the guard or the hook that answered for it, or that of the last result call. Or how it ended otherwise: a run-time error that nothing handled (RuntimeError), including one that the Class_Initialize of the object of a class module left unhandled, a module, a procedure or an interface the program does not have (NotFound), an End statement (Halted), or an invocation while another runs (Refused). None of these is an exception. A call, a guard, the factory, a hook or a result call ends the invocation as the procedure does.

Exceptions

ArgumentException

The invocation is not one a machine can run (Validate() lists the rules), and nothing runs.

ObjectDisposedException

The machine was disposed.

ResetAsync(CancellationToken)

Returns the machine to the state it was made in: releases the values it keeps for its invocations (MachineHeld), then its module-level variables and Static locals, running the Class_Terminate of each object released, closes its open files, clears its error state and restores its current directory.

Task<bool> ResetAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Cuts the reset short, between two instructions of a Class_Terminate or before the next one runs.

Returns

Task<bool>

true when the machine is back in the state it was made in; false when the token cut the reset short or an invocation is running. A machine whose reset answered false is not used again.

Exceptions

ObjectDisposedException

The machine was disposed.