40 lines
981 B
C#
40 lines
981 B
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
|
|
using MfGames.Gallium;
|
|
using MfGames.Nitride.Generators;
|
|
|
|
using NodaTime;
|
|
|
|
namespace MfGames.Nitride.Temporal;
|
|
|
|
/// <summary>
|
|
/// Filters out all entities that have an instant before the current
|
|
/// NitrideClock time.
|
|
/// </summary>
|
|
[WithProperties]
|
|
public partial class FilterOutFutureInstant : OperationBase
|
|
{
|
|
public FilterOutFutureInstant(TimeService timeService)
|
|
{
|
|
this.TimeService = timeService;
|
|
}
|
|
|
|
public TimeService TimeService { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public override IEnumerable<Entity> Run(
|
|
IEnumerable<Entity> input,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
Instant now = this.TimeService.Clock.GetCurrentInstant();
|
|
|
|
return input
|
|
.SelectEntity<Instant>(
|
|
(
|
|
entity,
|
|
instant) =>
|
|
instant.CompareTo(now) <= 0 ? entity : null);
|
|
}
|
|
}
|