Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created May 10, 2022 01:27
Show Gist options
  • Save rdelrosario/092ea6400d84ce46a026f20eb975c9e3 to your computer and use it in GitHub Desktop.
Save rdelrosario/092ea6400d84ce46a026f20eb975c9e3 to your computer and use it in GitHub Desktop.
public class StartupTaskBuilder
{
...
private class StartupTaskSequencer : IStartupTaskSequencer
{
public StartupTaskSequencer(Queue<IStartupTask> tasks) => _tasks = tasks;
public async Task StartAsync(IStartupTask task)
{
foreach (var next in _tasks.SkipWhile(x => x != task))
{
if (await next.CanRunAsync())
{
await next.RunAsync();
}
}
}
public Task StartAsync() => StartAsync(_tasks.FirstOrDefault());
private readonly Queue<IStartupTask> _tasks;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment