mfgames-cil/src/MfGames.Nitride/Pipelines/PipelineBase.cs

83 lines
2.3 KiB
C#

using MfGames.Gallium;
namespace MfGames.Nitride.Pipelines;
/// <summary>
/// A basic pipeline that is configured through properties and methods.
/// </summary>
public abstract class PipelineBase : IPipeline
{
private readonly List<IPipeline> dependencies;
protected PipelineBase()
{
this.dependencies = new List<IPipeline>();
}
/// <summary>
/// Adds add a pipeline dependencies into the current one. All of
/// the dependencies are guaranteed to run before this pipeline's RunAsync
/// is called.
/// </summary>
/// <param name="pipelines">The pipelines to add as a dependency.</param>
/// <returns>The same object for chaining operations.</returns>
public PipelineBase AddDependency(IPipeline pipeline)
{
this.dependencies.Add(pipeline);
return this;
}
/// <summary>
/// Adds one or more pipeline dependencies into the current one. All of
/// the dependencies are guaranteed to run before this pipeline's RunAsync
/// is called.
/// </summary>
/// <param name="pipelines">The pipelines to add as a dependency.</param>
/// <returns>The same object for chaining operations.</returns>
public PipelineBase AddDependencyList(params IPipeline[] pipelines)
{
foreach (IPipeline pipeline in pipelines)
{
this.AddDependency(pipeline);
}
return this;
}
/// <summary>
/// Adds one or more pipeline dependencies into the current one. All of
/// the dependencies are guaranteed to run before this pipeline's RunAsync
/// is called.
/// </summary>
/// <param name="pipelines">The pipelines to add as a dependency.</param>
/// <returns>The same object for chaining operations.</returns>
public PipelineBase AddDependency(IEnumerable<IPipeline> pipelines)
{
foreach (IPipeline pipeline in pipelines)
{
this.AddDependency(pipeline);
}
return this;
}
/// <inheritdoc />
public IEnumerable<IPipeline> GetDependencies()
{
return this.dependencies;
}
/// <inheritdoc />
public abstract IAsyncEnumerable<Entity> RunAsync(
IEnumerable<Entity> entities,
CancellationToken cancellationToken = default
);
/// <inheritdoc />
public override string ToString()
{
return this.GetType().Name;
}
}