@@ -12,9 +12,40 @@ On the other hand, it is very likely that developers will need to write [Tasks],
1212
1313## A sample Task
1414
15- Here is an annotated example of a [ Task] which makes use of a fictitious Action and a fictitious Question.
15+ Here is an annotated example of a [ Task] which makes use of a fictitious Action and Question.
1616
17- TODO: Write this docco
17+ ``` csharp
18+ // A parameter is constructor injected, so that this task may be parameterised.
19+ // This is entirely optional, if no parameters are needed then none need be added.
20+ public class BuyMilkIfNeeded (int cupsOfCoffee ) : IPerformable , ICanReport
21+ {
22+ // Always implement the ICanReport interface if possible.
23+ // Write a human-readable report of what the Task does.
24+ // There's no need to detail the work done by consumed performables; they will get their own reports.
25+ public ReportFragment GetReportFragment (Actor actor , IFormatsReportFragment formatter )
26+ => formatter .Format (" {Actor} adds milk to their shopping list, if they need it to make {Cups} cup(s) of coffee" , actor , cupsOfCoffee );
27+
28+ public async ValueTask PerformAsAsync (ICanPerform actor , CancellationToken cancellationToken = default )
29+ {
30+ // Use of a fictitious Question, remember to await it and to pass the cancellation token.
31+ // This question, which looks in the refridgerator and gets a decimal which represents the
32+ // quantity of an item inside, measured in litres, is ficitious.
33+ // It is consumed here from a fictitious builder method.
34+ var litresOfMilk = await actor .PerformAsync (LookInTheRefridgeratorFor (" Milk" ).AndTellMeHowMuchRemainsInLitres (), cancellationToken );
35+ var isEnough = IsThisEnoughMilkToMakeCoffee (cupsOfCoffee , litresOfMilk );
36+ if (! isEnough )
37+ // Use of a fictitious Action, again remember to await it and pass the cancellation token.
38+ await actor .PerformAsync (AddToMyShoppingList (" Milk" ), cancellationToken );
39+
40+ }
41+
42+ static bool IsThisEnoughMilkToMakeCoffee (int cupsOfCoffee , decimal litresOfMilk )
43+ {
44+ // Implementation omitted, determines if the litresOfMilk param is enough milk to make
45+ // the indicated number of cupsOfCoffee.
46+ }
47+ }
48+ ```
1849
1950[ Task ] : ../../glossary/Task.md
2051
0 commit comments