-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathProgram.cs
58 lines (51 loc) · 2.07 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Samples.HelloWorld;
using Stl.Fusion;
using static System.Console;
var services = new ServiceCollection()
// IncrementalBuilder service is the most important piece, check it out.
.AddFusion(f => f.AddService<IncrementalBuilder>())
.BuildServiceProvider();
var builder = services.GetRequiredService<IncrementalBuilder>();
// Creating projects
Project pAbstractions = new("Abstractions");
Project pClient = new("Client", pAbstractions.Id);
Project pUI = new("UI", pClient.Id);
Project pServer = new("Server", pUI.Id);
Project pConsoleClient = new("ConsoleClient", pClient.Id);
Project pAll = new("All", pServer.Id, pConsoleClient.Id);
var projects = new [] { pAbstractions, pClient, pUI, pServer, pConsoleClient, pAll };
WriteLine("Projects:");
var index = 1;
foreach (var project in projects) {
WriteLine($"{index++}. {project}");
await builder.AddOrUpdate(project);
}
Project InputProject(string prompt)
{
while (true) {
WriteLine($"{prompt} Type the number 1 ... {projects.Length}:");
var input = ReadLine();
if (int.TryParse(input, out var index) && index >= 1 && index <= projects.Length)
return projects[index - 1];
WriteLine("Wrong input.");
}
}
var watchedProject = InputProject("Which project do you want to continuously rebuild?");
_ = Task.Run(async () => {
WriteLine($"Watching: {watchedProject}");
var computed = await Computed.Capture(() => builder.GetOrBuild(watchedProject.Id, default));
while (true) {
WriteLine($"* Build result: {computed.Value}");
await computed.WhenInvalidated();
// Computed instances are ~ immutable, so update means getting a new one
computed = await computed.Update();
}
});
// Notice the code below doesn't even know there are some IComputed, etc.
while (true) {
await Task.Delay(1000); // Let's give a chance for building task to do its job
var invProject = InputProject("Project to invalidate?");
builder.InvalidateGetOrBuildResult(invProject.Id);
}