Skip to content

Commit a8044a6

Browse files
committed
Changed Resumers to reset automatically
1 parent 4a5a1e8 commit a8044a6

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

IResumer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ public interface IResumerBase {}
2727
public interface IResumer : IResumerBase
2828
{
2929
void Resume();
30-
void Reset();
3130
}
3231

3332
public interface IResumer<T> : IResumerBase
3433
{
3534
void Resume(T result);
36-
void Reset();
3735
}
3836
}

Internal/Context.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public ITask WaitForResumer(IResumer resumer)
127127
var _resumer = resumer as Resumer;
128128
if (_resumer.WasResumed)
129129
{
130+
_resumer.Reset();
130131
return continueTask;
131132
}
132133
_resumer.Setup(this);

Internal/Resumer.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ internal abstract class ResumerBase
3333

3434
public void Setup(Context context)
3535
{
36-
this.id = context.Id;
36+
Reset();
3737
this.context = context;
38+
id = context.Id;
3839
}
3940

4041
public virtual void Reset()
@@ -48,25 +49,22 @@ protected Context GetContext()
4849
{
4950
if (WasResumed)
5051
{
51-
throw new Exception("Attempted to re-resume an async resumer. You must call Reset() to use a resumer again.");
52+
throw new Exception("Attempted to re-resume an async resumer.");
5253
}
5354

54-
else if (context == null)
55+
if (context == null)
5556
{
5657
WasResumed = true;
5758
return null;
5859
}
5960

60-
else if (context.Id != id)
61+
if (context.Id != id)
6162
{
62-
Reset();
6363
return null;
6464
}
6565

6666
var _context = context;
67-
context = null;
68-
id = 0;
69-
WasResumed = true;
67+
Reset();
7068
return _context;
7169
}
7270
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public async Task WaitForEvent()
141141
Async.ReleaseResumer(resumer);
142142
}
143143
```
144-
Notice that IResumers are pooled and should be released when not needed. They can be re-used multiple times, but need to have their Reset() method called after each call to WaitForResumer.
144+
Notice that IResumers are pooled and should be released when not needed. They can be re-used multiple times, however.
145145

146146
IResumers are also "smart" about being called before being awaited upon.
147147
```cs

0 commit comments

Comments
 (0)