Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cleanup #9

Closed
wants to merge 4 commits into from
Closed
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
12 changes: 7 additions & 5 deletions src/Flo/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public TBuilder Fork(
Func<TIn, bool> predicate,
Action<TBuilder> configurePipeline)
{
return When(predicate, async (input, innerPipeline, next) =>
return When(predicate, (input, innerPipeline, next) =>
{
return await innerPipeline.Invoke(input);
return innerPipeline.Invoke(input);
},
configurePipeline);
}
Expand Down Expand Up @@ -70,15 +70,15 @@ public TBuilder When(

return Add(async (input, next) =>
{
var doInvoke = await predicate.Invoke(input);
var doInvoke = await predicate.Invoke(input).ConfigureAwait(false);
if (doInvoke)
{
var builder = CreateBuilder();
configurePipeline(builder);
return await handler.Invoke(input, builder.Build(), next);
return await handler.Invoke(input, builder.Build(), next).ConfigureAwait(false);
}

return await next.Invoke(input);
return await next.Invoke(input).ConfigureAwait(false);
});
}

Expand Down Expand Up @@ -140,5 +140,7 @@ public virtual Func<TIn, Task<TOut>> Build()
}

private static object DefaultServiceProvider(Type type) => Activator.CreateInstance(type);

protected static Task<TOut> CompletedEmptyOutTask = Task.FromResult(default(TOut));
}
}
2 changes: 1 addition & 1 deletion src/Flo/Flo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AssemblyName>Flo</AssemblyName>
<PackageId>Flo</PackageId>
<PackageProjectUrl>https://github.com/benfoster/flo</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/benfoster/Flo/raw/master/LICENSE.MD</PackageLicenseUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/benfoster/flo</RepositoryUrl>
<TargetFramework>netstandard1.3</TargetFramework>
Expand Down
10 changes: 5 additions & 5 deletions src/Flo/OutputPipelineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class OutputPipelineBuilder<TIn, TOut>
private static Func<TOut, bool> DefaultContinuation = output => output == null;

public OutputPipelineBuilder(Func<Type, object> serviceProvider = null)
: base(input => Task.FromResult(default(TOut)), serviceProvider)
: base(input => CompletedEmptyOutTask, serviceProvider)
{
}

Expand All @@ -20,11 +20,11 @@ public OutputPipelineBuilder<TIn, TOut> When(
{
return When(predicate, async (input, innerPipeline, next) =>
{
var result = await innerPipeline.Invoke(input);
var result = await innerPipeline.Invoke(input).ConfigureAwait(false);

// Continue on to the parent pipeline if the continueIf output predicate matches
if ((continueIf ?? DefaultContinuation).Invoke(result))
return await next.Invoke(input);
return await next.Invoke(input).ConfigureAwait(false);

return result;
},
Expand All @@ -38,11 +38,11 @@ public OutputPipelineBuilder<TIn, TOut> When(
{
return When(predicate, async (input, innerPipeline, next) =>
{
var result = await innerPipeline.Invoke(input);
var result = await innerPipeline.Invoke(input).ConfigureAwait(false);

// Continue on to the parent pipeline if the continueIf output predicate matches
if ((continueIf ?? DefaultContinuation).Invoke(result))
return await next.Invoke(input);
return await next.Invoke(input).ConfigureAwait(false);

return result;
},
Expand Down
10 changes: 4 additions & 6 deletions src/Flo/PipelineBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Flo
Expand All @@ -9,7 +8,6 @@ public class PipelineBuilder<T> : Builder<T, T, PipelineBuilder<T>> // : Builder
public PipelineBuilder(Func<Type, object> serviceProvider = null)
: base(input => Task.FromResult(input), serviceProvider)
{
InnerHandler = input => Task.FromResult(input);
}

public PipelineBuilder<T> When(
Expand All @@ -18,8 +16,8 @@ public PipelineBuilder<T> When(
{
return When(predicate, async (input, innerPipeline, next) =>
{
input = await innerPipeline.Invoke(input);
return await next.Invoke(input);
input = await innerPipeline.Invoke(input).ConfigureAwait(false);
return await next.Invoke(input).ConfigureAwait(false);
},
configurePipeline);
}
Expand All @@ -30,8 +28,8 @@ public PipelineBuilder<T> When(
{
return When(predicate, async (input, innerPipeline, next) =>
{
input = await innerPipeline.Invoke(input);
return await next.Invoke(input);
input = await innerPipeline.Invoke(input).ConfigureAwait(false);
return await next.Invoke(input).ConfigureAwait(false);
},
configurePipeline);
}
Expand Down
1 change: 0 additions & 1 deletion test/Flo.Tests/OutputPipelineBuilderForkTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using NSpec;
using Shouldly;
Expand Down