|
1 | 1 | # DependencyQueue |
2 | 2 |
|
3 | | -A .NET dependency queue implementation: a thread-safe, generic queue that |
4 | | -dequeues elements in dependency order. |
| 3 | +A dependency queue for .NET: a thread-safe, generic queue that dequeues |
| 4 | +elements in dependency order. |
5 | 5 |
|
6 | 6 | ## Status |
7 | 7 |
|
8 | | -WIP |
| 8 | +[](https://github.com/sharpjs/DependencyQueue/actions) |
| 9 | +[](https://www.nuget.org/packages/DependencyQueue) |
| 10 | +[](https://www.nuget.org/packages/DependencyQueue) |
| 11 | + |
| 12 | +- **Tested:** 100% coverage by automated tests. |
| 13 | +- **Documented:** IntelliSense on everything. Guide below. |
9 | 14 |
|
10 | 15 | ## Installation |
11 | 16 |
|
12 | | -WIP |
| 17 | +Install [this NuGet Package](https://www.nuget.org/packages/DependencyQueue) in your project. |
13 | 18 |
|
14 | 19 | ## Usage |
15 | 20 |
|
16 | | -WIP |
| 21 | +Let's imagine a program that cooks a basic hamburger. The program can add |
| 22 | +steps to a dependency queue in any order, and the queue will yield back the |
| 23 | +steps in the correct order to prepare a burger. |
| 24 | + |
| 25 | +```csharp |
| 26 | +// Create a queue |
| 27 | +using var queue = new DependencyQueue<Step>(); |
| 28 | + |
| 29 | +// Create a builder for queue entries |
| 30 | +var builder = queue.CreateEntryBuilder(); |
| 31 | + |
| 32 | +// Add entries in any order |
| 33 | +builder |
| 34 | + .NewEntry("Assembly", burgerAssembler) |
| 35 | + .AddRequires("GrilledPatty", "ToastedBun", "Lettuce", "Tomato", "Onion", "Sauce") |
| 36 | + .Enqueue(); |
| 37 | +builder |
| 38 | + .NewEntry("Gathering", fridgeRaider) |
| 39 | + .AddProvides("Patty", "Bun", "Lettuce", "Tomato", "Onion") |
| 40 | + .Enqueue(); |
| 41 | +builder |
| 42 | + .NewEntry("Grilling", griller) |
| 43 | + .AddRequires("Patty") |
| 44 | + .AddProvides("GrilledPatty") |
| 45 | + .Enqueue(); |
| 46 | +builder |
| 47 | + .NewEntry("Toasting", toaster) |
| 48 | + .AddRequires("Bun") |
| 49 | + .AddProvides("ToastedBun") |
| 50 | + .Enqueue(); |
| 51 | + |
| 52 | +// Validate the queue |
| 53 | +var errors = queue.Validate(); |
| 54 | +if (errors.Any()) |
| 55 | + throw new InvalidBurgerException(); |
| 56 | + |
| 57 | +// Now build the burger |
| 58 | +while (queue.TryDequeue() is Step step) |
| 59 | + step.Execute(); |
| 60 | +``` |
| 61 | + |
| 62 | +TODO: Expand |
| 63 | + |
| 64 | +### Queue Runs |
| 65 | + |
| 66 | +TODO: Describe |
| 67 | + |
| 68 | +```csharp |
| 69 | +await queue.RunAsync( |
| 70 | + async (x, d) => …, |
| 71 | + parallelism: 4, |
| 72 | + cancellationToken |
| 73 | +); |
| 74 | +``` |
17 | 75 |
|
18 | 76 | <!-- |
19 | 77 | Copyright Subatomix Research Inc. |
|
0 commit comments