Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CancellationToken to TextReader.ReadXAsync #61898

Merged
merged 10 commits into from
Jan 25, 2022
Prev Previous commit
Next Next commit
Apply suggestions from code review
  • Loading branch information
adamsitnik authored Jan 25, 2022
commit 967b98131431786d28cc44b9c1a2640dcca0509d
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public override string ReadToEnd()
/// </summary>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A value task that represents the asynchronous read operation. The value of the <c>TResult</c>
/// parameter contains the next line from the string reader, or is <c>null</c> if all of the characters have been read.</returns>
/// parameter contains the next line from the string reader, or is <see langword="null" /> if all of the characters have been read.</returns>
/// <exception cref="ArgumentOutOfRangeException">The number of characters in the next line is larger than <see cref="int.MaxValue"/>.</exception>
/// <exception cref="ObjectDisposedException">The string reader has been disposed.</exception>
/// <exception cref="InvalidOperationException">The reader is currently in use by a previous read operation.</exception>
Expand All @@ -244,8 +244,8 @@ public override string ReadToEnd()
/// stringToRead.AppendLine("and the end");
///
/// string readText;
/// using var tokenSource = new CancellationTokenSource();
/// using var reader = new StringReader(stringToRead.ToString());
/// using CancellationTokenSource tokenSource = new (TimeSpan.FromSeconds(1));
/// using StringReader reader = new (stringToRead.ToString());
/// while ((readText = await reader.ReadLineAsync(tokenSource.Token)) is not null)
/// {
/// Console.WriteLine(readText);
Expand Down Expand Up @@ -281,8 +281,8 @@ public override Task<string> ReadToEndAsync()
/// stringToRead.AppendLine("and 2nd line");
/// stringToRead.AppendLine("and the end");
///
/// using var tokenSource = new CancellationTokenSource();
/// using var reader = new StringReader(stringToRead.ToString());
/// using CancellationTokenSource tokenSource = new (TimeSpan.FromSeconds(1));
/// using StringReader reader = new (stringToRead.ToString());
/// var readText = await reader.ReadToEndAsync(tokenSource.Token);
/// Console.WriteLine(readText);
/// </code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public virtual int ReadBlock(Span<char> buffer)
/// </summary>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A value task that represents the asynchronous read operation. The value of the <c>TResult</c>
/// parameter contains the next line from the text reader, or is <c>null</c> if all of the characters have been read.</returns>
/// parameter contains the next line from the text reader, or is <see langword="null" /> if all of the characters have been read.</returns>
/// <exception cref="ArgumentOutOfRangeException">The number of characters in the next line is larger than <see cref="int.MaxValue"/>.</exception>
/// <exception cref="ObjectDisposedException">The text reader has been disposed.</exception>
/// <exception cref="InvalidOperationException">The reader is currently in use by a previous read operation.</exception>
Expand All @@ -219,7 +219,7 @@ public virtual int ReadBlock(Span<char> buffer)
/// your code. For an example of using the <see cref="ReadLineAsync(CancellationToken)"/> method, see the
/// <see cref="StreamReader.ReadLineAsync(CancellationToken)"/> method.</para>
/// <para>If the current <see cref="TextReader"/> represents the standard input stream returned by
/// the <c>Console.In</c> property, the <see cref="ReadLineAsync(CancellationToken)"/> method
/// the <see cref="Console.In" /> property, the <see cref="ReadLineAsync(CancellationToken)"/> method
/// executes synchronously rather than asynchronously.</para>
/// </remarks>
public virtual ValueTask<string?> ReadLineAsync(CancellationToken cancellationToken) =>
bgrainger marked this conversation as resolved.
Show resolved Hide resolved
Expand Down