public static IAsyncCommandBuilder <T> Add <T>(this IAsyncCommandBuilder <T> builder, Action <T, CancellationToken> action) => builder.Add(new Command <T>((c, ct) => { action(c, ct); return(c); }).ToAsync());
public static IAsyncCommandBuilder <T> Add <T>(this IAsyncCommandBuilder <T> builder, AsyncContextHandler <T> action) => builder.Add(new AsyncCommand <T>(async(c, ct) => { await action(c, ct).ConfigureAwait(false); return(c); }));
public static IAsyncCommandBuilder <T> AddIf <T>(this IAsyncCommandBuilder <T> builder, Predicate <T> predicate, AsyncContextHandler <T> action) => builder.Add(new AsyncCommand <T>(async(i, ct) => { if (predicate(i)) { await action(i, ct).ConfigureAwait(false); } return(i); }));
public static IAsyncCommandBuilder <T> If <T>(this IAsyncCommandBuilder <T> builder, Predicate <T> predicate, Func <IAsyncCommandBuilder <T>, IAsyncCommandBuilder <T> > command) => builder.Add(new AsyncCommand <T>((async(context, ct) => { if (predicate(context)) { var innerCommand = command(new AsyncCommandBuilder <T>()).Build(); await innerCommand.ExecuteAsync(context, ct).ConfigureAwait(false); } return(context); })));
public static IAsyncCommandBuilder <T> AddIf <T>(this IAsyncCommandBuilder <T> builder, Predicate <T> predicate, AsyncContextTransformation <T> action) => builder.Add(new AsyncCommand <T>((i, ct) => predicate(i) ? action(i, ct) : Task.FromResult(i)));
public static IAsyncCommandBuilder <T> Add <T>(this IAsyncCommandBuilder <T> builder, Func <T, CancellationToken, T> transform) => builder.Add(new Command <T>(transform).ToAsync());
public static IAsyncCommandBuilder <T> Add <T>(this IAsyncCommandBuilder <T> builder, AsyncContextTransformation <T> action) => builder.Add(new AsyncCommand <T>(action));
/// <summary> /// Adds a command step which throws the specified exception. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TContext"></typeparam> /// <param name="builder"></param> /// <param name="exception"></param> /// <returns></returns> public static IAsyncCommandBuilder <TContext> Throw <T, TContext>(this IAsyncCommandBuilder <TContext> builder, T exception) where T : Exception where TContext : class => builder.Add(new AsyncCommand <TContext>((_, _) => throw exception));