-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
45 lines (35 loc) · 1.43 KB
/
Program.cs
File metadata and controls
45 lines (35 loc) · 1.43 KB
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
using System;
using System.Threading.Tasks;
namespace H.Necessaire.Samples.Resilience
{
internal class Program
{
static async Task Main(string[] args)
{
OperationResult resultA = await DoSomeWorkAlignedWithResilientPattern(logger: null);
OperationResult resultB = await WrapSomeWorkWitResilientPattern(logger: null);
OperationResult[] allResults = [resultA, resultB];
OperationResult globalResult = allResults.Merge();
//Implement flow based on OperationResult.IsSuccessful
}
static async Task<OperationResult> DoSomeWorkAlignedWithResilientPattern(ImALogger logger)
{
if (logger is null)
return OperationResult.Fail($"{nameof(logger)} is null. A logger must be provided.");
await logger.LogInfo("Doing some work");
return OperationResult.Win();
}
static async Task<OperationResult> WrapSomeWorkWitResilientPattern(ImALogger logger)
{
OperationResult result = OperationResult.Fail("Work not yet started");
await new Func<Task>(async () =>
{
await logger.LogInfo("Doing some work");
})
.TryOrFailWithGrace(
onFail: ex => result = OperationResult.Fail(ex, $"Error occurred while trying to do work. Reason: {ex.Message}.")
);
return result;
}
}
}