public async Task Whens(CancellationToken token)
{
try
{
if (behavior.Whens.Count != 0)
{
await Task.Run(async () =>
{
var executedWhens = new List<Guid>();
while (!token.IsCancellationRequested)
{
if (executedWhens.Count == behavior.Whens.Count)
{
break;
}
if (token.IsCancellationRequested)
{
break;
}
foreach (var when in behavior.Whens)
{
if (token.IsCancellationRequested)
{
break;
}
if (executedWhens.Contains(when.Id))
{
continue;
}
if (await when.ExecuteAction(scenarioContext, endpointInstance).ConfigureAwait(false))
{
executedWhens.Add(when.Id);
}
}
}
}, token).ConfigureAwait(false);
}
}
catch (Exception ex)
{
Logger.Error($"Failed to execute Whens on endpoint{configuration.EndpointName}", ex);
throw;
}
}