Skip to content

Commit

Permalink
Some minor improvements to samples.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Jan 17, 2024
1 parent 00fbabe commit 4811b4f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
13 changes: 8 additions & 5 deletions src/samples/cancellation/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
await OutAsync("Reading cooked input: ");
await OutLineAsync(await ReadLineAsync());
await OutAsync("Reading cooked input and cancelling after 5 seconds: ");

await OutLineAsync("Entering raw mode and reading input. Then canceling after 5 seconds.");
using var cts1 = new CancellationTokenSource(delay: TimeSpan.FromSeconds(5));

await OutLineAsync(await ReadLineAsync(cts1.Token));

await OutLineAsync("Entering raw mode and reading input. Then cancelling after 5 seconds.");
await OutLineAsync();

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

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
using var cts2 = new CancellationTokenSource(delay: TimeSpan.FromSeconds(5));

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

while (true)
{
try
{
if (await ReadAsync(array, cts.Token) == 0)
if (await ReadAsync(array, cts2.Token) == 0)
break;
}
catch (OperationCanceledException)
Expand Down
2 changes: 1 addition & 1 deletion src/samples/processes/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
await OutLineAsync("Launching 'bash'...");

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
using var cts = new CancellationTokenSource(delay: TimeSpan.FromSeconds(10));

var bash =
new ChildProcessBuilder()
Expand Down
14 changes: 8 additions & 6 deletions src/samples/sounds/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const int Volume = 3;

await OutAsync(
new ControlBuilder()
.PlayNotes(3, 2, [1, 3, 5])
.PlayNotes(3, 8, [6, 10, 8, 11])
.PlayNotes(3, 4, [10, 11, 13, 10])
.PlayNotes(3, 8, [8, 11])
.PlayNotes(3, 4, [10, 11, 13, 10, 11, 13, 15, 17])
.PlayNotes(3, 8, [18, 17, 18]));
.PlayNotes(Volume, duration: 2, [1, 3, 5])
.PlayNotes(Volume, duration: 8, [6, 10, 8, 11])
.PlayNotes(Volume, duration: 4, [10, 11, 13, 10])
.PlayNotes(Volume, duration: 8, [8, 11])
.PlayNotes(Volume, duration: 4, [10, 11, 13, 10, 11, 13, 15, 17])
.PlayNotes(Volume, duration: 8, [18, 17, 18]));

0 comments on commit 4811b4f

Please sign in to comment.