Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions dotnet/src/ActionDisposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/

namespace GitHub.Copilot.SDK;

/// <summary>
/// A disposable that invokes an action when disposed.
/// </summary>
internal sealed class ActionDisposable : IDisposable
{
private Action? _action;

public ActionDisposable(Action action)
{
_action = action;
}

public void Dispose()
{
var action = Interlocked.Exchange(ref _action, null);
action?.Invoke();
}
}
19 changes: 0 additions & 19 deletions dotnet/src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,22 +1561,3 @@ public class ToolResultAIContent(ToolResultObject toolResult) : AIContent
{
public ToolResultObject Result => toolResult;
}

/// <summary>
/// A disposable that invokes an action when disposed.
/// </summary>
internal sealed class ActionDisposable : IDisposable
{
private Action? _action;

public ActionDisposable(Action action)
{
_action = action;
}

public void Dispose()
{
var action = Interlocked.Exchange(ref _action, null);
action?.Invoke();
}
}
7 changes: 1 addition & 6 deletions dotnet/src/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void Handler(SessionEvent evt)
public IDisposable On(SessionEventHandler handler)
{
_eventHandlers.Add(handler);
return new OnDisposeCall(() => _eventHandlers.Remove(handler));
return new ActionDisposable(() => _eventHandlers.Remove(handler));
}

/// <summary>
Expand Down Expand Up @@ -600,11 +600,6 @@ await InvokeRpcAsync<object>(
}
}

private class OnDisposeCall(Action callback) : IDisposable
{
public void Dispose() => callback();
}

internal record SendMessageRequest
{
public string SessionId { get; init; } = string.Empty;
Expand Down