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

The Archive Base Latest Questions

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

I want to: Immediately subscribe to an IObservable<T> , but immediately start buffering any

  • 0

I want to:

  1. Immediately subscribe to an IObservable<T>, but immediately start buffering any T that is received (i.e. not yet seen by my IObserver<T>).
  2. Do some work.
  3. When the work is completed, flush the buffer to my IObserver<T> and continue

It is quite important that the subscription is the first thing that happens.

In a ‘marble diagram’ form I am after something like this…

Time                  T+1   2   3   4   5   6   7   8
s1:IObservable<int>     1   2   3   4   5   6   7   8  
s2:IObservable<bool>          t    
r: IObservable<int>           1 3   4   5   6   7   8
                              2

… in that at T+1 I subscribe to an IObservable<bool> r that itself is dependent upon IObservable<int> s1 and IObservable<bool> s2. s1 is a stream that I don’t control, s2 is one that I do control (a Subject), and publish on when the work is done.

I thought that SkipUntil would help me out, but that doesn’t buffer the events that are received before the dependent IObservable has completed.

Here’s some code that I thought would work, but doesn’t due to SkipUntil not being a buffer.

        var are = new AutoResetEvent(false);
        var events = Observable.Generate(1, i => i < 12, i => i + 1, i => i, i => TimeSpan.FromSeconds(1));

        events.Subscribe(x => Console.WriteLine("events:" + x), () => are.Set());

        var subject = new Subject<int>();
        var completed = subject.AsObservable().Delay(TimeSpan.FromSeconds(5));

        Console.WriteLine("Subscribing to events...");

        events.SkipUntil(completed).Subscribe(x=> Console.WriteLine("events.SkipUntil(completed):"+ x));
        Console.WriteLine("Subscribed.");

        completed.Subscribe(x => Console.WriteLine("Completed"));

        subject.OnNext(10);

        are.WaitOne();
        Console.WriteLine("Done");

I know about the various Buffer methods but they don’t seem appropriate in this case as I am not really buffering here, just coordinating activity at the start of my subscriptions.

UPDATE

I have generalised Enigmativity’s response into the following extension method that might be useful:

public static class ObservableEx
{
    public static IObservable<TSource> BufferUntil<TSource, TCompleted>(this IObservable<TSource> source, IObservable<TCompleted> completed)
    {
        var observable = Observable.Create<TSource>(o =>
        {
            var replaySubject = new ReplaySubject<TSource>();
            var sub1 = source.Subscribe(replaySubject);
            var query =
                completed.Take(1).Select(
                    x => replaySubject.AsObservable());
            var sub2 = query.Switch().Subscribe(o);
            return new CompositeDisposable(sub1, sub2);
        });
        return observable;
    }        
}
  • 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-25T19:38:07+00:00Added an answer on May 25, 2026 at 7:38 pm

    This works for me:

    var r = Observable.Create<int>(o =>
    {
        var rs = new ReplaySubject<int>();
        var subscription1 = s1.Subscribe(rs);
        var query = from f in s2.Take(1) select rs.AsObservable();
        var subscription2 = query.Switch().Subscribe(o);
        return new CompositeDisposable(subscription1, subscription2);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some PHP that I don't want loaded immediately. Is it possible to
I want to create a listview that immediately when initialized in the onCreate() method
I have a webservice that I want to query for updates immediately after a
I want to write a program, which search some HTML addresses. I assume that
I want to know if it is possible to Immediately receive a message that
I want a certain route to immediately redirect to /50 index: Ember.Route.extend({ route: '/',
Hi : I want to run an operation immediately after Guice hydrates my class
What if I want to do something with my formset other than immediately saving
After creating a child process and exiting it immediately (_exit()), I want to perform
I am opening a new iOS development company and want to start selling my

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.