dotnet / dotnet/reactive

Unexpected blocking behavior with Repeat

Open
#1,105 16 comments 0 reactions 0 assignees View on GitHub
[area] Rx
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Description

This is actually distilled from a much more complicated debugging session, which boils down to the following query:

```c#
using System;
using System.Linq;
using System.Reactive.Linq;

namespace Recursive
{
class Program
{
static void Main(string[] args)
{
var timer = Observable
.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1))
.SelectMany(x => Observable.
Return(x)
.Repeat()
.Do(k => Console.WriteLine(k))
.TakeWhile((k, i) => i <= k));
timer.Subscribe();
Console.ReadLine();
}
}
}
```

In my understanding, this query should repeat the value N as many times as N, and then stop, but for some reason it loops forever on the **Repeat**, even though **TakeWhile** is clearly terminating, as can be verified by moving the **WriteLine** right after the **TakeWhile** operator (it will return zero once and then nothing, as opposed to an infinite stream of zeroes when it's right after **Repeat**).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.