Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a more usefull LongRunningApplicationSubscription over IDisposable #14

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/Proc/Proc.StartLongRunning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@

namespace ProcNet
{
public class LongRunningApplicationSubscription : IDisposable
{
internal LongRunningApplicationSubscription(ObservableProcess process, CompositeDisposable subscription)
{
Process = process;
Subscription = subscription;
}

private IDisposable Subscription { get; }

public ObservableProcess Process { get; }

public bool SendControlC(int processId) => Process.SendControlC(processId);
public void SendControlC() => Process.SendControlC();

public void Dispose()
{
Subscription?.Dispose();
Process?.Dispose();
}
}

public static partial class Proc
{

Expand All @@ -28,7 +50,7 @@ public static partial class Proc
/// <para>defaults to <see cref="ConsoleOutColorWriter"/> which writes standard error messages in red</para>
/// </param>
/// <returns>The exit code and whether the process completed</returns>
public static IDisposable StartLongRunning(LongRunningArguments arguments, TimeSpan waitForStartedConfirmation, IConsoleOutWriter consoleOutWriter = null)
public static LongRunningApplicationSubscription StartLongRunning(LongRunningArguments arguments, TimeSpan waitForStartedConfirmation, IConsoleOutWriter consoleOutWriter = null)
{
var started = false;
var confirmWaitHandle = new ManualResetEvent(false);
Expand Down Expand Up @@ -71,7 +93,7 @@ public static IDisposable StartLongRunning(LongRunningArguments arguments, TimeS
else
{
var completed = confirmWaitHandle.WaitOne(waitForStartedConfirmation);
if (completed) return composite;
if (completed) return new(process, composite);
var pwd = arguments.WorkingDirectory;
var args = arguments.Args.NaivelyQuoteArguments();
var printBinary = arguments.OnlyPrintBinaryInExceptionMessage
Expand All @@ -80,7 +102,7 @@ public static IDisposable StartLongRunning(LongRunningArguments arguments, TimeS
throw new ProcExecException($"Could not yield started confirmation after {waitForStartedConfirmation} while running {printBinary}");
}

return composite;
return new(process, composite);
}
}
}
Loading