IApplicationLaunchReply interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IApplicationLaunchReply

The running instance's side of a reply to a forwarded launch: messages to the launching process, then its exit status. One launching process, for example a command line, reads them while the running instance does the work.

Remarks

Members can be called from any thread; writes are sent one at a time, in order. A write waits while the launching process does not read, so a slow reader slows the writer instead of filling memory.

Properties

CancelRequested

CancellationToken CancelRequested { get; }

Cancelled when the launching process asks to cancel with IForwardedLaunchReply.CancelAsync, for example on Ctrl+C. It keeps reading messages until the reply completes.

Remarks

Pass this token rather than IApplicationLaunchReply.Cancelled to work that should outlive the launching process, such as an operation a command line started over SSH: it is not cancelled when the connection drops. The default implementation returns IApplicationLaunchReply.Cancelled, for a reply that cannot tell the two apart; the replies Runic creates implement it.

Cancelled

CancellationToken Cancelled { get; }

Cancelled when the launching process asks to cancel (for example on Ctrl+C), when it goes away, or when this instance ends: IApplicationLaunchReply.CancelRequested or IApplicationLaunchReply.Disconnected, which is cancelled first, so a callback registered on this token can tell which. After a cancel request the launching process still reads messages until the reply completes.

Disconnected

CancellationToken Disconnected { get; }

Cancelled when the reply ends without an exit status: the launching process went away or closed it (disposing its reply, or cancelling a read), this instance ended, or a write here was cancelled. Writes then return false.

Remarks

The default implementation returns IApplicationLaunchReply.Cancelled, for a reply that cannot tell the two apart; the replies Runic creates implement it.

Methods

CompleteAsync

ValueTask CompleteAsync(int exitCode, CancellationToken cancellationToken = default)

Sends exitCode after the messages written before and ends the reply. The launching process waits until it is called, or until this instance ends.

Parameters

exitCode

The launching process's exit status, for example 0, or 130 after a cancel request.

cancellationToken

Stops waiting for a launching process that does not read, ending the reply.

Exceptions

InvalidOperationException

The reply was already completed.

WriteAsync

ValueTask<bool> WriteAsync(string message, CancellationToken cancellationToken = default)

Sends one message, such as an output line or a JSON event, as UTF-8.

Parameters

message

At most 1 MiB in UTF-8.

cancellationToken

Stops waiting for a launching process that does not read. A write cancelled this way ends the reply, since the launching process may have received only part of the message.

Returns

False, without sending, once the launching process went away or this instance ended.

Exceptions

ArgumentException

message is larger than 1 MiB in UTF-8.

InvalidOperationException

The reply was completed.