Skip to content

Commit

Permalink
cancellation source instead of wait
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes committed Dec 11, 2024
1 parent 6695d97 commit 565caa7
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Sentry.Unity.Android/JniExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,14 @@ private void DoWork()
{
lock (_lock)
{
using var timeoutCts = new CancellationTokenSource(Timeout);
_taskCompletionSource = new TaskCompletionSource<object?>();
_currentTask = jniOperation;
_taskEvent.Set();

try
{
if (!_taskCompletionSource.Task.Wait(Timeout))
{
throw new TimeoutException($"JNI operation timed out after {Timeout.Milliseconds}ms");
}
_taskCompletionSource.Task.Wait(timeoutCts.Token);
return (TResult?)_taskCompletionSource.Task.Result;
}
catch (Exception e)
Expand All @@ -121,16 +119,14 @@ public void Run(Action jniOperation)
{
lock (_lock)
{
using var timeoutCts = new CancellationTokenSource(Timeout);
_taskCompletionSource = new TaskCompletionSource<object?>();
_currentTask = jniOperation;
_taskEvent.Set();

try
{
if (!_taskCompletionSource.Task.Wait(Timeout))
{
throw new TimeoutException($"JNI operation timed out after {Timeout.Milliseconds}ms");
}
_taskCompletionSource.Task.Wait(timeoutCts.Token);
}
catch (Exception e)
{
Expand Down

0 comments on commit 565caa7

Please sign in to comment.