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 8149963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:57:19+00:00 2026-06-06T14:57:19+00:00

This is an academic exercise, I’m new to Reactive Extensions and trying to get

  • 0

This is an academic exercise, I’m new to Reactive Extensions and trying to get my head around the technology. I set myself a goal of making an IObservable that returns successive digits of Pi (I happen to be really interested in Pi right at the moment for unrelated reasons). Reactive Extensions contains operators for making observables, the guidance they give is that you should “almost never need to create your own IObsevable”. But I can’t see how I can do this with the ready-made operators and methods. Let me elucidate a bit more.

I was planning to use an algorithm that would involve the expansion of a Taylor series for Arctan. To get the next digit of Pi, I’d expand a few more terms in the series.

So I need the series expansion going on asynchronously, occasionally throwing out the next computed digit to the IObserver. I obviosly don’t want to restart the computation from scratch for each new digit.

Is there a way to implement this behaviour using RX’s built-in operators, or am I going to have to code an IObservable from scratch? What strategy suggests itself?

  • 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-06-06T14:57:20+00:00Added an answer on June 6, 2026 at 2:57 pm

    Simplest way is to create an Enumerable and then convert it:

    IEnumerable<int> Pi()
    {
        // algorithm here
        for (int i = 0; i < 1000; i++)
        {
            yield return i;
        }
    }
    

    Usage (for a cold observable, that is every new ‘subscription’ starts creating Pi from scratch):

    var cold = Pi().ToObservable(Scheduler.ThreadPool);
    cold.Take(5).Subscribe(Console.WriteLine);
    

    If you want to make it hot (everyone shares the same underlying calculation), you can just do this:

    var hot = cold.Publish().RefCount();
    

    Which will start the calculation after the first subscriber, and stop it when they all disconnect. Here’s a simple test:

    hot.Subscribe(p => Console.WriteLine("hot1: " + p));
    Thread.Sleep(5);    
    hot.Subscribe(p => Console.WriteLine("hot2: " + p));    
    

    Which should show hot1 printing only for a little while, then hot2 joining in after a short wait but printing the same numbers. If this was done with cold, the two subscriptions would each start from 0.

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

Sidebar

Related Questions

In an effort to get better at programming assembly, and as an academic exercise,
I'm brand spanking new to WPF and am trying to play around with projects
I'm trying to write a C++ application on Gnome/Ubuntu as my first non-academic exercise
so...I'm trying to learn this new thing called closures... new for me.... Out of
As something of an academic exercise, I thought I'd try to get my unit
This question is mostly academic. I ask out of curiosity, not because this poses
This is kind of an academic question, so feel free to exit now. I've
This is really just sort of an academic question, I'm just curious to know
This may seem to be an academic question, but still I would be very
Disclaimer: This question is strictly academic. The example I'm about to give is probably

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.