Skip to content

Commit

Permalink
Return a more usefull LongRunningApplicationSubscription over IDispos…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
Mpdreamz committed Jan 16, 2024
1 parent c01278c commit 64e4338
Showing 1 changed file with 25 additions and 3 deletions.
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);
}
}
}

0 comments on commit 64e4338

Please sign in to comment.