Skip to content

Commit 3da7bb2

Browse files
author
Oren (electricessence)
committed
Added additional OnFullfilled handler
1 parent 874b1fd commit 3da7bb2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Open.Threading.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Part of the "Open" set of libraries.</Description>
1111
<PackageLicenseUrl>https://github.com/electricessence/Open.Threading/blob/master/LISCENSE.md</PackageLicenseUrl>
1212
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
13-
<Version>1.1.4</Version>
13+
<Version>1.1.5</Version>
1414
<AssemblyVersion>1.0.0.1</AssemblyVersion>
1515
<FileVersion>1.0.0.1</FileVersion>
1616
<Copyright>https://github.com/electricessence/Open.Threading/blob/master/LISCENSE.md</Copyright>

TaskExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ public static TTask OnFullfilled<TTask>(this TTask target, Action action)
7878
return target;
7979
}
8080

81+
/// <summary>
82+
/// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if completed and not cancelled.
83+
/// </summary>
84+
/// <typeparam name="TTask">The return type is the same as the target.</typeparam>
85+
/// <param name="action">The action to perform if fullfulled.</param>
86+
/// <returns>The target object. Allows for method chaining.</returns>
87+
public static Task<T> OnFullfilled<T>(this Task<T> target, Action<T> action)
88+
{
89+
target.ContinueWith(task =>
90+
{
91+
if (task.Status == TaskStatus.RanToCompletion) action(task.Result);
92+
});
93+
94+
return target;
95+
}
96+
8197
/// <summary>
8298
/// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if completed and not cancelled.
8399
/// </summary>

0 commit comments

Comments
 (0)