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 (TimeSpan interval, Func< DateTimeOffset, IMsg > fn)
 Returns a cmd that, when dispatched, waits interval after the last dispatch before invoking fn .
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 (TimeSpan interval, Func< DateTimeOffset, IMsg > fn)
 Returns a cmd that forwards at most one invocation per interval .
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.

◆ Debounce()

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

Returns a cmd that, when dispatched, waits interval after the last dispatch before invoking fn .

If re-dispatched within the window the previous pending invocation is cancelled and the window resets.

Note: debouncing state is held in the returned closure. Use a single stored reference to the same cmd instance across re-dispatches for correct behaviour.

◆ 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 ( TimeSpan interval,
Func< DateTimeOffset, IMsg > fn )
static

Returns a cmd that forwards at most one invocation per interval .

Calls within the throttle window are dropped (not delayed).

◆ 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