ConsoleForge 0.3.0
Elm-architecture TUI framework for .NET 8
Loading...
Searching...
No Matches
ConsoleForge.Core.Cmd Class Reference

Factory for creating common command values. More...

Static Public Member Functions

static ? ICmd Batch (params ICmd?[] cmds)
 Run all commands concurrently.
static ICmd Debounce (string key, TimeSpan interval, Func< DateTimeOffset, IMsg > fn)
 Invokes fn once interval has passed without another dispatch under key .
static ICmd Msg (IMsg msg)
 Returns the given message immediately (synchronous, no async gap).
static ICmd Quit ()
 Returns QuitMsg immediately, ending the program loop.
static ICmd Run (Func< CancellationToken, Task< IMsg > > fn)
 Wrap an async function as a command.
static ICmd Run (Func< CancellationToken, Task< IMsg > > fn, CancellationToken cancellationToken)
 Wrap an async function as a command, binding a specific CancellationToken at creation time.
static ? ICmd Sequence (params ICmd?[] cmds)
 Run commands serially: each waits for the previous to complete.
static ICmd Throttle (string key, TimeSpan interval, Func< DateTimeOffset, IMsg > fn)
 Invokes fn at most once per interval under key , on the leading edge.
static ICmd Tick (TimeSpan interval, Func< DateTimeOffset, IMsg > fn, CancellationToken cancellationToken=default)
 Fire once after interval .

Static Public Attributes

static readonly? ICmd None = null
 No-op command. Framework skips dispatch.

Detailed Description

Factory for creating common command values.

Member Function Documentation

◆ Batch()

? ICmd ConsoleForge.Core.Cmd.Batch ( params ICmd?[] cmds)
static

Run all commands concurrently.

Null commands filtered out. Returns null if zero cmds remain; the single cmd if one remains. Each command's message is delivered as soon as that command completes — batching is NOT a barrier (a slow fetch doesn't delay a fast tick). Nesting is safe: an inner Batch dispatches its own children the same way.

◆ Debounce()

ICmd ConsoleForge.Core.Cmd.Debounce ( string key,
TimeSpan interval,
Func< DateTimeOffset, IMsg > fn )
static

Invokes fn once interval has passed without another dispatch under key .

Re-dispatching inside the window supersedes the pending invocation and restarts it; the superseded one produces no message at all.

The window belongs to key and is held by the running App, not by the returned cmd, so a cmd built fresh in Update — the only way the Elm loop builds one — debounces correctly. The most recent fn under a key is the one that runs, so a closure that varies per item is safe.

Keys are namespaced by the application, as subscription keys are. A window still open when the program exits is cancelled rather than fired.

Parameters
keyIdentifies the window. Dispatches sharing it supersede one another.

◆ Msg()

ICmd ConsoleForge.Core.Cmd.Msg ( IMsg msg)
static

Returns the given message immediately (synchronous, no async gap).

Useful when a model update needs to dispatch a follow-up message (e.g. ThemeChangedMsg) in the same event-loop tick.

◆ Run()

ICmd ConsoleForge.Core.Cmd.Run ( Func< CancellationToken, Task< IMsg > > fn)
static

Wrap an async function as a command.

fn receives a CancellationToken that is cancelled when the program is shutting down.

◆ Sequence()

? ICmd ConsoleForge.Core.Cmd.Sequence ( params ICmd?[] cmds)
static

Run commands serially: each waits for the previous to complete.

Null commands filtered out.

◆ Throttle()

ICmd ConsoleForge.Core.Cmd.Throttle ( string key,
TimeSpan interval,
Func< DateTimeOffset, IMsg > fn )
static

Invokes fn at most once per interval under key , on the leading edge.

Dispatches inside the window are dropped rather than delayed, and produce no message.

As with Debounce, the window is held by the running App against key , so a cmd built fresh in Update throttles correctly. Keys persist for the life of the program — throttle against a fixed key, not a per-item identifier.

Parameters
keyIdentifies the window. Dispatches sharing it share one rate limit.

◆ Tick()

ICmd ConsoleForge.Core.Cmd.Tick ( TimeSpan interval,
Func< DateTimeOffset, IMsg > fn,
CancellationToken cancellationToken = default )
static

Fire once after interval .

Returns fn(timestamp) as the message. Pass a CancellationToken to allow cancellation on program shutdown.


The documentation for this class was generated from the following file:
  • src/ConsoleForge/Core/Cmd.cs