Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions IteratorTasks.Extensions/IteratorTasks.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Compile Include="TaskEx.cs" />
<Compile Include="TaskExtensions.cs" />
<Compile Include="TaskUtility.cs" />
<Compile Include="TaskUtility_Success.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IteratorTasks\IteratorTasks.csproj">
Expand Down
2 changes: 1 addition & 1 deletion IteratorTasks.Extensions/TaskUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace IteratorTasks
/// 特に、タイマー関連は、マルチスレッドになってしまうので Unity とは相性よくないかも。
/// Unity は yield return new WaitForSeconds(t); とか使ってほしそうだし。
/// </remarks>
public static class TaskUtility
public static partial class TaskUtility
{
/// <summary>
/// 二重起動防止付きのタスク生成関数を返す。
Expand Down
72 changes: 72 additions & 0 deletions IteratorTasks.Extensions/TaskUtility_Success.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;

namespace IteratorTasks
{
public static partial class TaskUtility
{

public static Task OnSuccess(this Task t, Action succesHandler)
{
return t.ContinueWith(x =>
{
succesHandler();
}, true);
}

public static Task OnSuccess<T>(this Task<T> t, Action<T> succesHandler)
{
return t.ContinueWith(x =>
{
succesHandler(t.Result);
}, true);
}

public static Task<T> OnSuccess<T>(this Task t, Func<T> succesHandler)
{
return t.ContinueWith<T>(x =>
{
return succesHandler();
}, true);
}

public static Task<U> OnSuccess<T, U>(this Task<T> t, Func<T, U> succesHandler)
{
return t.ContinueWith<U>(x =>
{
return succesHandler(t.Result);
}, true);
}

public static Task OnSuccessWithTask(this Task t, Func<Task> succesHandler)
{
return t.ContinueWithTask(x =>
{
return succesHandler();
}, true);
}

public static Task OnSuccessWithTask<T>(this Task<T> t, Func<T, Task> succesHandler)
{
return t.ContinueWithTask(x =>
{
return succesHandler(t.Result);
}, true);
}

public static Task<T> OnSuccessWithTask<T>(this Task t, Func<Task<T>> succesHandler)
{
return t.ContinueWithTask<T>(x =>
{
return succesHandler();
}, true);
}

public static Task<U> OnSuccessWithTask<T, U>(this Task<T> t, Func<T, Task<U>> succesHandler)
{
return t.ContinueWithTask<U>(x =>
{
return succesHandler(t.Result);
}, true);
}
}
}