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

  • Home
  • SEARCH
  • 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 9259701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:43:05+00:00 2026-06-18T12:43:05+00:00

I’m trying to figure out how to create a Reactive subscription for an event

  • 0

I’m trying to figure out how to create a Reactive subscription for an event not followed by a different event within a specific time window.

To illustrate, here’s a use case:

A busy indicator triggered by two events. Busy and NotBusy. They may fire close together but the indicator should not flash on/off too often.

When NotBusy fires, there should be no indicator. When Busy fires and NotBusy hasn’t fired within 5 seconds then it should display.

Is there a way to do this entirely within Reactive without adding external state?

  • 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-18T12:43:06+00:00Added an answer on June 18, 2026 at 12:43 pm

    Ah, I can’t resist – how often do you get to counter-answer the author of the source material? (see Benjol’s comment on question) 🙂

    Here’s my stab at it (LINQPad-ready):

    Output looks like this:

    At 1/1/0001 12:00:00 AM +00:00, Busy Signal Indicator is now:OFF
    Sending BUSY at 1/1/0001 12:00:00 AM +00:00
    Sending NOTBUSY at 1/1/0001 12:00:02 AM +00:00
    
    Sending BUSY at 1/1/0001 12:00:03 AM +00:00
    Sending BUSY at 1/1/0001 12:00:06 AM +00:00
    At 1/1/0001 12:00:08 AM +00:00, Busy Signal Indicator is now:ON
    Sending NOTBUSY at 1/1/0001 12:00:09 AM +00:00
    At 1/1/0001 12:00:09 AM +00:00, Busy Signal Indicator is now:OFF
    

    Here a basic definition of our events:

    enum EventType 
    { 
        Busy, 
        NotBusy 
    }
    class StreamEvent 
    { 
         public EventType Type {get; set;} 
         public StreamEvent(EventType type) { Type = type;}
    }
    

    And here’s the query + test code:

    void Main()
    {
        // our simulated event stream
        var fakeSource = new System.Reactive.Subjects.Subject<StreamEvent>();
    
        // Let's use a scheduler we actually don't have to wait for
        var theTardis = new System.Reactive.Concurrency.HistoricalScheduler();
    
        var busySignal = fakeSource
            // Batch up events:
            .Window(
                // Starting batching on a busy signal
                fakeSource.Where(e => e.Type == EventType.Busy),
                // Stop batching on a not busy signal
                (open) => fakeSource.Where(e => e.Type == EventType.NotBusy)
                    // but throw a timeout if we exceed 5 seconds per window
                    .Timeout(TimeSpan.FromSeconds(5), theTardis))       
            // Unpack the windows
            .Switch()
            // Catch any timeout exception and inject a NULL into the stream        
            .Catch(fakeSource.StartWith((StreamEvent)null))
            // Bool-ify on "did a timeout happen?"
            .Select(e => e == null)
            // Start in an "unbusy" state
            .StartWith(false)
            // And only tell us about transitions
            .DistinctUntilChanged();    
    
        using(busySignal.Subscribe(signal => 
            Console.WriteLine("At {0}, Busy Signal Indicator is now:{1}",
                theTardis.Now,
                signal ? "ON" : "OFF")))
        {
            // should not generate a busy signal
            Console.WriteLine("Sending BUSY at {0}", theTardis.Now);
            fakeSource.OnNext(new StreamEvent(EventType.Busy));
            theTardis.AdvanceBy(TimeSpan.FromSeconds(2));
            Console.WriteLine("Sending NOTBUSY at {0}", theTardis.Now);
            fakeSource.OnNext(new StreamEvent(EventType.NotBusy));
            theTardis.AdvanceBy(TimeSpan.FromSeconds(1));
            Console.WriteLine();
    
            // should generate a busy signal
            Console.WriteLine("Sending BUSY at {0}", theTardis.Now);
            fakeSource.OnNext(new StreamEvent(EventType.Busy));
            theTardis.AdvanceBy(TimeSpan.FromSeconds(3));
            Console.WriteLine("Sending BUSY at {0}", theTardis.Now);
            fakeSource.OnNext(new StreamEvent(EventType.Busy));
            theTardis.AdvanceBy(TimeSpan.FromSeconds(3));
    
            // and this should clear it
            Console.WriteLine("Sending NOTBUSY at {0}", theTardis.Now);
            fakeSource.OnNext(new StreamEvent(EventType.NotBusy));      
            theTardis.AdvanceBy(TimeSpan.FromSeconds(1));
            Console.WriteLine();    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.