Skip to content

Instantly share code, notes, and snippets.

@shmutalov
Created August 13, 2020 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shmutalov/07f1746696822ff67bf44b10caffbf66 to your computer and use it in GitHub Desktop.
Save shmutalov/07f1746696822ff67bf44b10caffbf66 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
namespace KekPuk.Extensions
{
/// <summary>
/// Task extension methods
/// </summary>
public static class TaskExt
{
public static async Task<TOut> AndThen<TIn, TOut>(this Task<TIn> inputTask, Func<TIn, Task<TOut>> mapperFunc)
{
if (mapperFunc == null) throw new ArgumentNullException(nameof(mapperFunc));
return await mapperFunc(await inputTask);
}
public static async Task AndThen<TIn>(this Task<TIn> inputTask, Action<TIn> mapperFunc)
{
if (mapperFunc == null) throw new ArgumentNullException(nameof(mapperFunc));
mapperFunc(await inputTask);
}
public static async Task<TOut> AndThen<TIn, TOut>(this TIn inputTask, Func<TIn, Task<TOut>> mapperFunc)
{
if (mapperFunc == null) throw new ArgumentNullException(nameof(mapperFunc));
return await mapperFunc(inputTask);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment