Skip to content

Commit

Permalink
Update Recording_Named.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 4, 2023
1 parent 172facb commit c332df5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Verify/Recording/Recording_Named.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

public static partial class Recording
{

static ConcurrentDictionary<string, State> namedState = new(StringComparer.OrdinalIgnoreCase);

public static void Add(string identifier, string name, object item) =>
Expand Down Expand Up @@ -60,12 +59,20 @@ static State CurrentStateNamed(string identifier, [CallerMemberName] string call
throw new($"Recording.Start(string identifier) must be called before Recording.{caller}");
}

public static void Start(string identifier)
public static IDisposable Start(string identifier)
{
if (!namedState.TryAdd(identifier, new()))
{
throw new("Recording already started");
}
return new NamedDisposable(identifier);
}

class NamedDisposable(string identifier) :
IDisposable
{
public void Dispose() =>
Pause(identifier);
}

public static void Pause(string identifier) =>
Expand Down

0 comments on commit c332df5

Please sign in to comment.