相关疑难解决方法(0)

为什么在所有初始订户断开连接后RefCount无法正常工作?

考虑以下:

[Fact]
public void foo()
{
    var result = new Subject<bool>();
    var startCount = 0;
    var completionCount = 0;
    var obs = Observable
        .Defer(() =>
            {
                ++startCount;
                return result.FirstAsync();
            })
        .Do(_ => ++completionCount)
        .Publish()
        .RefCount();

    // pretend there are lots of subscribers at once
    var s1 = obs.Subscribe();
    var s2 = obs.Subscribe();
    var s3 = obs.Subscribe();

    // even so, we only expect to be started once
    Assert.Equal(1, startCount);
    Assert.Equal(0, completionCount);

    // and we won't complete until the result ticks through …
Run Code Online (Sandbox Code Playgroud)

.net c# system.reactive

7
推荐指数
1
解决办法
156
查看次数

标签 统计

.net ×1

c# ×1

system.reactive ×1