-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #905 from kekekeks/proposed_fix_for_886
Proposed fix for #886 asp.net deadlock
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Akka.Util.Internal | ||
{ | ||
public static class TaskExtensions | ||
{ | ||
public static Task<TResult> CastTask<TTask, TResult>(this Task<TTask> task) | ||
{ | ||
if (task.IsCompleted) | ||
return Task.FromResult((TResult) (object)task.Result); | ||
var tcs = new TaskCompletionSource<TResult>(); | ||
if (task.IsFaulted) | ||
tcs.SetException(task.Exception); | ||
else | ||
task.ContinueWith(_ => | ||
{ | ||
if (task.IsFaulted || task.Exception != null) | ||
tcs.SetException(task.Exception); | ||
else if (task.IsCanceled) | ||
tcs.SetCanceled(); | ||
else | ||
try | ||
{ | ||
tcs.SetResult((TResult) (object) task.Result); | ||
} | ||
catch (Exception e) | ||
{ | ||
tcs.SetException(e); | ||
} | ||
}, TaskContinuationOptions.ExecuteSynchronously); | ||
return tcs.Task; | ||
} | ||
} | ||
} |