Created
March 25, 2022 13:15
-
-
Save rdelrosario/6ae3d80397e4ca291dea8022df89de75 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class StartupTaskBuilder | |
| { | |
| public StartupTaskBuilder() => _tasks = new Queue<IStartupTask>(); | |
| public StartupTaskBuilder Add(IStartupTask task) | |
| { | |
| QueueTask(task); | |
| return this; | |
| } | |
| public IStartupTaskSequencer Build() => new StartupTaskSequencer(_tasks); | |
| private void QueueTask(IStartupTask task) => _tasks.Enqueue(task); | |
| private readonly Queue<IStartupTask> _tasks; | |
| private class StartupTaskSequencer : IStartupTaskSequencer | |
| { | |
| public StartupTaskSequencer(Queue<IStartupTask> tasks) => _tasks = tasks; | |
| public async Task StartAsync() | |
| { | |
| foreach(var next in _tasks) | |
| { | |
| if (await next.CanRunAsync()) | |
| { | |
| await next.RunAsync(); | |
| } | |
| } | |
| } | |
| private readonly Queue<IStartupTask> _tasks; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment