Skip to content

Commit c332df5

Browse files
committed
Update Recording_Named.cs
1 parent 172facb commit c332df5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Verify/Recording/Recording_Named.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
public static partial class Recording
44
{
5-
65
static ConcurrentDictionary<string, State> namedState = new(StringComparer.OrdinalIgnoreCase);
76

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

63-
public static void Start(string identifier)
62+
public static IDisposable Start(string identifier)
6463
{
6564
if (!namedState.TryAdd(identifier, new()))
6665
{
6766
throw new("Recording already started");
6867
}
68+
return new NamedDisposable(identifier);
69+
}
70+
71+
class NamedDisposable(string identifier) :
72+
IDisposable
73+
{
74+
public void Dispose() =>
75+
Pause(identifier);
6976
}
7077

7178
public static void Pause(string identifier) =>

0 commit comments

Comments
 (0)