Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6802303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:12:25+00:00 2026-05-26T19:12:25+00:00

I’m trying to expand my knowledge on Rx. So I’m just playing around with

  • 0

I’m trying to expand my knowledge on Rx. So I’m just playing around with streams and try to make them behave as I would expect them to do.

While I have read bevor that the Repeat() operator has difficulties in practice because you could loose notifications between the OnCompleted and the re-subscription, I can’t figure out on my own why the following happens.

        var subject = new Subject<string>();

        var my = subject
            .Take(1)
            .Merge(Observable.Empty<string>().Delay(TimeSpan.FromMilliseconds(2000)))
            .Repeat();
        my.Subscribe(Console.WriteLine);

        var stopwatch = new Stopwatch();
        stopwatch.Start();
        Scheduler.ThreadPool.Schedule(TimeSpan.FromSeconds(1), () => subject.OnNext("1 at " + stopwatch.ElapsedMilliseconds));
        Scheduler.ThreadPool.Schedule(TimeSpan.FromSeconds(2), () => subject.OnNext("2 at " + stopwatch.ElapsedMilliseconds));
        Scheduler.ThreadPool.Schedule(TimeSpan.FromSeconds(3), () => subject.OnNext("3 at " + stopwatch.ElapsedMilliseconds));
        Scheduler.ThreadPool.Schedule(TimeSpan.FromSeconds(4), () => subject.OnNext("4 at " + stopwatch.ElapsedMilliseconds));
        Scheduler.ThreadPool.Schedule(TimeSpan.FromSeconds(5), () => subject.OnNext("5 at " + stopwatch.ElapsedMilliseconds));
        Scheduler.ThreadPool.Schedule(TimeSpan.FromSeconds(6), () => subject.OnNext("6 at " + stopwatch.ElapsedMilliseconds));

        Console.ReadLine();

When I run this example the results are totally non-deterministic:

Result 1:

1 at 1006
3 at 3007
5 at 4995

It’s good that it left out the 2 and 4 but even inside this result there is some strangeness because actually between the 3 and the 5 is no real 2 seconds gap.

However, the results can be even worse. See this one:

1 at 1003
2 at 2003
4 at 4005
6 at 6004

There is no 2 seconds gap between 1 and 2. It’s exactly one second. Why didn’t he left it out?

If anyone could clarify things for me, I would be more than happy!

EDIT

I just noticed that it might be the Merge that is wrong here. If I refactor my query to Concat things seem to happen as they should:

        var my = subject
            .Take(1)
            .Concat(Observable.Empty<string>().Delay(TimeSpan.FromMilliseconds(2000)))
            .Repeat();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:12:26+00:00Added an answer on May 26, 2026 at 7:12 pm

    Windows (and other desktop OSes) is not a runtime OS and so you can’t rely that its timers will be precise down to milliseconds. And especially if you have more timers, this can lead to non-deterministic behavior, which is exactly your case.

    This is how your original sequence works:

    • time ~ 0
      • Take(1) subscribes to subject
      • timer for the delayed empty observable starts ticking
    • time ~ 1
      • 1 is added to subject, 1 is written out; after this point, nobody subscribes to subject anymore
    • time ~ 2
      • timer for the delayed empty observable runs out. Because of that, Take(1) subscribes to subject again and another timer for delayed empty observable starts
      • at about the same time, 2 is added to subject

    Because of slight differences in timing, the two actions at time approx. 2 can happen in any order. And the order matters, either 2 is added before Take() resubscribes or before. And thus, 2 can be written out, or not.

    If what you want is a sequence like this:

    1. wait for first item and return it
    2. wait about two seconds
    3. wait for second item and return it (ignoring any that were added during the two-second wait)
    4. …

    then I think the code in your edit is right.

    But this in no way guarantees deterministic results. On my computer, if I change the wait time of the delayed empty observable to 1960 ms, I get non-deterministic results when using Concat().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.