-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented CancellationToken on Read() (#35)
- Added asynchronous read operation that can be cancelled using a CancellationToken.
- Loading branch information
Showing
6 changed files
with
136 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using ConsoulLibrary.Views; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ConsoulLibrary.Test.Views | ||
{ | ||
public class CancellabelReadView : StaticView | ||
{ | ||
public CancellabelReadView() | ||
{ | ||
Title = (new BannerEntry("Testing the Read(CancellationToken) method")).Message; | ||
} | ||
|
||
[ViewOption("Test Read()")] | ||
public void Test() | ||
{ | ||
Consoul.Write("Input some text:", ConsoleColor.Yellow); | ||
string input = Consoul.Read(); | ||
Consoul.Write("Read the following input:"); | ||
Consoul.Write(input, ConsoleColor.Gray); | ||
|
||
Consoul.Wait(); | ||
} | ||
|
||
[ViewOption("Test Read(CancellationToken)")] | ||
public void TestCancellable() | ||
{ | ||
const int TIMEOUT_SECONDS = 5; | ||
string input = string.Empty; | ||
Consoul.Write("Input some text:", ConsoleColor.Yellow); | ||
using (var cancelSource = new CancellationTokenSource(TimeSpan.FromSeconds(TIMEOUT_SECONDS))) | ||
{ | ||
cancelSource.Token.Register(() => Consoul.Write("Consoul.Read(CancellationToken) Timed Out!", ConsoleColor.Red)); | ||
input = Consoul.Read(cancelSource.Token); | ||
} | ||
Consoul.Write("Read the following input:"); | ||
Consoul.Write(input, ConsoleColor.Gray); | ||
|
||
Consoul.Wait(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters