IntroToRx: Creating Observable Sequences

Open Beginner friendly
#2,183 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
70/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp
Domain
documentation

Research direction

Open Rx.NET/Documentation/IntroToRx/03_CreatingObservableSequences.md and locate the Observable.Create section linked in the issue. Check the file-reading snippet's cancellation condition, correct it so reading continues until cancellation, and verify the documented code matches the supplied corrected example.

Written by the indexing model from the issue text.

Description

[area] Rx
Bug

Which library version?

The issue is in the documentation of the library, not in a specific version of the library itself.

What are the platform(s), environment(s) and related component version(s)?

Not applicable.

What is the use case or problem?

There is a typo in the documentation code snippet for reading file lines using Observable.Create.
https://github.com/dotnet/reactive/blob/main/Rx.NET/Documentation/IntroToRx/03_CreatingObservableSequences.md#observablecreate

What is the expected outcome?

The code snippet should correctly handle the cancellation token in the while loop.

What is the actual outcome?

The current code uses while (cancellationToken.IsCancellationRequested) which will break the loop when the cancellation is requested. It should use while (!cancellationToken.IsCancellationRequested) instead.

What is the stacktrace of the exception(s) if any?

Not applicable.

Do you have a code snippet or project that reproduces the problem?

Yes, here is the corrected code snippet:

IObservable<string> ReadFileLines(string path) =>
    Observable.Create<string>(async (observer, cancellationToken) =>
    {
        using (StreamReader reader = File.OpenText(path))
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                string? line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false);
                if (line is null)
                {
                    break;
                }

                observer.OnNext(line);
            }

            observer.OnCompleted();
        }
    });
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/reactive

All issues in dotnet/reactive

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.