Skip to content

Commit 4811b4f

Browse files
committed
Some minor improvements to samples.
1 parent 00fbabe commit 4811b4f

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/samples/cancellation/Program.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
await OutAsync("Reading cooked input: ");
2-
await OutLineAsync(await ReadLineAsync());
1+
await OutAsync("Reading cooked input and cancelling after 5 seconds: ");
32

4-
await OutLineAsync("Entering raw mode and reading input. Then canceling after 5 seconds.");
3+
using var cts1 = new CancellationTokenSource(delay: TimeSpan.FromSeconds(5));
4+
5+
await OutLineAsync(await ReadLineAsync(cts1.Token));
6+
7+
await OutLineAsync("Entering raw mode and reading input. Then cancelling after 5 seconds.");
58
await OutLineAsync();
69

710
var array = new byte[1];
@@ -14,15 +17,15 @@
1417
{
1518
await Task.Delay(TimeSpan.FromSeconds(5));
1619

17-
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
20+
using var cts2 = new CancellationTokenSource(delay: TimeSpan.FromSeconds(5));
1821

1922
await OutAsync($"Round {i}...\r\n");
2023

2124
while (true)
2225
{
2326
try
2427
{
25-
if (await ReadAsync(array, cts.Token) == 0)
28+
if (await ReadAsync(array, cts2.Token) == 0)
2629
break;
2730
}
2831
catch (OperationCanceledException)

src/samples/processes/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
await OutLineAsync("Launching 'bash'...");
22

3-
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
3+
using var cts = new CancellationTokenSource(delay: TimeSpan.FromSeconds(10));
44

55
var bash =
66
new ChildProcessBuilder()

src/samples/sounds/Program.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
const int Volume = 3;
2+
13
await OutAsync(
24
new ControlBuilder()
3-
.PlayNotes(3, 2, [1, 3, 5])
4-
.PlayNotes(3, 8, [6, 10, 8, 11])
5-
.PlayNotes(3, 4, [10, 11, 13, 10])
6-
.PlayNotes(3, 8, [8, 11])
7-
.PlayNotes(3, 4, [10, 11, 13, 10, 11, 13, 15, 17])
8-
.PlayNotes(3, 8, [18, 17, 18]));
5+
.PlayNotes(Volume, duration: 2, [1, 3, 5])
6+
.PlayNotes(Volume, duration: 8, [6, 10, 8, 11])
7+
.PlayNotes(Volume, duration: 4, [10, 11, 13, 10])
8+
.PlayNotes(Volume, duration: 8, [8, 11])
9+
.PlayNotes(Volume, duration: 4, [10, 11, 13, 10, 11, 13, 15, 17])
10+
.PlayNotes(Volume, duration: 8, [18, 17, 18]));

0 commit comments

Comments
 (0)