Skip to content

Commit afaa607

Browse files
committed
Refactor SharpCasterTaskCompletionSource methods
- Updated constructor to use TaskCreationOptions.RunContinuationsAsynchronously for better async handling. - Changed SetResult and SetException methods to TrySetResult and TrySetException to avoid exceptions when tasks are already completed. - Removed the TaskCompletionMethod enum as it is no longer needed.
1 parent 795a42b commit afaa607

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

Sharpcaster/Models/SharpCasterTaskCompletionSource.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@ public class SharpCasterTaskCompletionSource
1111

1212
public SharpCasterTaskCompletionSource()
1313
{
14-
_tcs = new TaskCompletionSource<string>();
14+
_tcs = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);
1515
}
1616

1717
public void SetResult(string parameter)
1818
{
19-
_tcs.SetResult(parameter);
19+
_tcs.TrySetResult(parameter);
2020
}
2121

2222
public void SetException(Exception exception)
2323
{
24-
_tcs.SetException(exception);
24+
_tcs.TrySetException(exception);
2525
}
2626
}
27-
28-
public enum TaskCompletionMethod
29-
{
30-
SetResult,
31-
SetException
32-
}
3327
}

0 commit comments

Comments
 (0)