ElmishRuntimeType

PackageAxial.ElmishFlows

ElmishRuntime

ElmishRuntime<'env> owns the root scope for all commands in one Elmish program. Create one per program with ElmishRuntime.start, passing an environment and a Post function that delivers callbacks on the host's dispatch thread.

Construction

ElmishRuntime.start options environment builds a runtime from ElmishRuntimeOptions (Post, OnDefect, HistoryCapacity, Clock, LogSink). Clock = None and LogSink = None keep the live runtime defaults; Some clock installs that clock for commands, subscriptions and layer provisioning, and Some sink replaces the default log sink there. When already on the dispatch thread, Post should run inline; otherwise it should post to it. Do not call Elmish's dispatch directly from workers. Connect OnDefect to the host's crash reporting path; typed failures are messages, but defects are not.

The runtime accepts any environment and needs no clock member. Keep the environment stable, and supply a command's current dependencies with Flow.localEnv.

Services

runtime |> ElmishRuntime.startService name service starts a Flow<'env, Never, unit> as a named fiber in the runtime's root scope, outside the Elmish program, so init and update never start or restart it. It returns Result<unit, ServiceStartError>: Error ServiceStartError.DuplicateName while a service with that name is still running, and Error ServiceStartError.RuntimeStopping once the runtime is stopping. Stopping the runtime interrupts the service. A defect goes to OnDefect under the service name, and so does a service that completes while the runtime is still running, because a service is expected to run until the runtime stops.

Unlike Cmd.OfFlow.start, which the program runs from init or update and which is expected to finish, a service is started by the host, one per name, and reports whether it started.

Shutdown

  • runtime.StopAndWait timeout interrupts commands and subscriptions, waits for their finalizers, and returns false on timeout; it is safe from a single-threaded UI context.
  • runtime.Stop() is the asynchronous alternative.

Specification

Kind
Type
Members
8
Examples
0
startSignature
ElmishRuntime.start options environment
startLayerSignature
ElmishRuntime.startLayer options layer input
startServiceSignature
ElmishRuntime.startService name service runtime
testSignature
ElmishRuntime.test clock environment
StopSignature
this.Stop

Summary

NameSignatureSynopsis
Operations
startElmishRuntime.start options environmentStarts a runtime around a caller-supplied environment.
startLayerElmishRuntime.startLayer options layer inputStarts a runtime by provisioning a layer inside the runtime's root scope.
startServiceElmishRuntime.startService name service runtimeStarts a long-lived service flow owned by the runtime, outside the Elmish program.
testElmishRuntime.test clock environmentCreates a runtime with queued dispatch and captured defects for tests.
Stopthis.StopNo description available.
StopAndWaitthis.StopAndWaitNo description available.
Environmentthis.EnvironmentNo description available.
Registrythis.RegistryNo description available.

Operations

kind:member

start

ElmishRuntime.start options environment
Member
Starts a runtime around a caller-supplied environment.

Parameters

NameTypeDescription
optionsElmishRuntimeOptionsHost delivery and diagnostic policy.
environment'envThe application dependencies every command runs with.

Returns

ElmishRuntime<'env>
kind:member

startLayer

ElmishRuntime.startLayer options layer input
Member
Starts a runtime by provisioning a layer inside the runtime's root scope.

Parameters

NameTypeDescription
optionsElmishRuntimeOptionsHost delivery and diagnostic policy.
layerLayer<'input, 'error, 'env>The layer that builds the runtime's environment.
input'inputThe input environment required to build the layer.

Returns

Async<Result<ElmishRuntime<'env>, 'error>>
kind:member

startService

ElmishRuntime.startService name service runtime
Member
Starts a long-lived service flow owned by the runtime, outside the Elmish program.

Parameters

NameTypeDescription
namestringThe service fiber's diagnostic name; one running service per name.
serviceFlow<'env, Never, unit>The Flow<'env, Never, unit> to run for the program's lifetime.
runtimeElmishRuntime<'env>The runtime that owns the service.

Returns

Result<unit, ServiceStartError>
kind:member

test

ElmishRuntime.test clock environment
Member
Creates a runtime with queued dispatch and captured defects for tests.

Parameters

NameTypeDescription
clockManualClock
environment'env

Returns

TestRuntime<'env>
kind:member

Stop

this.Stop
Member

Returns

Async<unit>
kind:member

StopAndWait

this.StopAndWait
Member

Parameters

NameTypeDescription
timeoutTimeSpan

Returns

bool
kind:member

Environment

this.Environment
Member

Returns

'env
kind:member

Registry

this.Registry
Member

Returns

FiberRegistry