-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: segment can handle a single route sub-part of a pipeline (#94)
- Loading branch information
Showing
5 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Streamistry.Fluent; | ||
public class BinderBuilder<TInput, TOutput> : PipeElementBuilder<TInput, TOutput> | ||
{ | ||
protected Segment<TInput, TOutput> Segment { get; } | ||
|
||
public BinderBuilder(IPipeBuilder<TInput> upstream, Segment<TInput, TOutput> segment) | ||
: base(upstream) | ||
=> (Segment) = (segment); | ||
|
||
public override IChainablePort<TOutput> OnBuildPipeElement() | ||
{ | ||
var upstream = Upstream.BuildPipeElement(); | ||
var (input, output) = Segment.Craft(upstream.Pipe.Pipeline!); | ||
input.Bind(upstream); | ||
return output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Streamistry.Observability; | ||
|
||
namespace Streamistry.Fluent; | ||
|
||
public class Segment<TInput, TOutput> : IPipeBuilder<TInput> | ||
{ | ||
private VirtualInput<TInput> Input { get; set; } = new(); | ||
internal Func<BasePipeBuilder<TInput>, BasePipeBuilder<TOutput>> Builder { get; } | ||
|
||
public Segment(Func<BasePipeBuilder<TInput>, BasePipeBuilder<TOutput>> builder) | ||
=> Builder = builder; | ||
|
||
public IChainablePort<TInput> BuildPipeElement() | ||
=> Input ??= (VirtualInput<TInput>)OnBuildPipeElement(); | ||
|
||
public IChainablePort<TInput> OnBuildPipeElement() | ||
=> new VirtualInput<TInput>(); | ||
|
||
public (IBindablePipe<TInput> input, IChainablePort<TOutput>) Craft(Pipeline pipeline) | ||
{ | ||
Input.Pipeline = pipeline; | ||
var builder = Builder.Invoke(Input); | ||
builder.Build(); | ||
return (Input.GetTarget(), builder.BuildPipeElement()); | ||
} | ||
|
||
private class VirtualInput<T> : BasePipeBuilder<T>, IChainablePort<T>, IChainablePipe | ||
{ | ||
private IBindablePipe<T>? Target { get; set; } | ||
|
||
public IChainablePipe Pipe | ||
=> this; | ||
|
||
public Pipeline? Pipeline { get; set; } | ||
|
||
public IBindablePipe<T> GetTarget() | ||
=> Target ?? throw new InvalidOperationException(); | ||
|
||
public void RegisterDownstream(Action<T?> downstream) | ||
=> Target ??= (IBindablePipe<T>)downstream.Target!; | ||
|
||
public void UnregisterDownstream(Action<T?> downstream) | ||
=> Target ??= (IBindablePipe<T>)downstream.Target!; | ||
|
||
|
||
public void RegisterOnCompleted(Action? complete) | ||
{ | ||
if (complete is not null) | ||
Target ??= (IBindablePipe<T>)complete.Target!; | ||
} | ||
|
||
public override IChainablePort<T> OnBuildPipeElement() | ||
=> this; | ||
|
||
public void RegisterObservability(ObservabilityProvider? provider) => throw new NotImplementedException(); | ||
public ObservabilityProvider? GetObservabilityProvider() => null; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters