build: initial project release
All checks were successful
release / dotnet-release-workflow (push) Successful in 1m23s

This commit is contained in:
Louis Seubert 2026-01-20 22:41:16 +01:00
commit 48c483c568
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
62 changed files with 4957 additions and 0 deletions

View file

@ -0,0 +1,94 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
using System.Runtime.CompilerServices;
namespace Geekeey.Process;
/// <summary>
/// Represents an asynchronous execution of a command.
/// </summary>
public sealed partial class CommandTask<TResult> : IDisposable
{
private readonly Process _process;
internal CommandTask(Task<TResult> task, Process process, int processId)
{
Task = task;
_process = process;
ProcessId = processId;
}
/// <summary>
/// Underlying task.
/// </summary>
public Task<TResult> Task { get; }
/// <summary>
/// Underlying process ID.
/// </summary>
public int ProcessId { get; }
internal CommandTask<T> Bind<T>(Func<Task<TResult>, Task<T>> transform)
{
return new CommandTask<T>(transform(Task), _process, ProcessId);
}
/// <summary>
/// Lazily maps the result of the task using the specified transform.
/// </summary>
internal CommandTask<T> Select<T>(Func<TResult, T> transform)
{
return Bind(async task => transform(await task));
}
/// <summary>
/// Signals the process with an interrupt request from the keyboard.
/// </summary>
public void Interrupt()
{
_process.Interrupt();
}
/// <summary>
/// Immediately stops the associated process and its descendent processes.
/// </summary>
public void Kill()
{
_process.Kill();
}
/// <summary>
/// Gets the awaiter of the underlying task.
/// Used to enable await expressions on this object.
/// </summary>
public TaskAwaiter<TResult> GetAwaiter()
{
return Task.GetAwaiter();
}
/// <summary>
/// Configures an awaiter used to await this task.
/// </summary>
public ConfiguredTaskAwaitable<TResult> ConfigureAwait(bool continueOnCapturedContext)
{
return Task.ConfigureAwait(continueOnCapturedContext);
}
/// <inheritdoc />
public void Dispose()
{
Task.Dispose();
}
}
public sealed partial class CommandTask<TResult>
{
/// <summary>
/// Converts the command task into a regular task.
/// </summary>
public static implicit operator Task<TResult>(CommandTask<TResult> commandTask)
{
return commandTask.Task;
}
}