2

       return Observable
            .Timer(TimeSpan.FromSeconds(2))
            .SelectAsync(delegate { return this.getResponse(request); })
            .Repeat()
            .Timeout(TimeSpan.FromSeconds(10), Observable.Return(new InMemoryDataSetIsGoodResponse(false, "Connection to Mongo timed out after 10 seconds."))
            .SkipWhile(r => r.IsGood)
            .Take(1)
            .StartWith(new InMemoryDataSetIsGoodResponse(true, null)));

I want to poll a database to make sure that a particular record is still in the database. getResponse returns an IsGood response as long as the record is there, then it returns a bad response.

I just want to start with the assumption that it's there and do nothing until it's bad, at which point I just want to publish the bad response once and be done with it.

But an observer sees an IsGood response every two seconds. Can anyone explain that?

masonk
  • 9,176
  • 2
  • 47
  • 58
  • Regardless of what everything before `Take(1)` does, an observer should see at most 2 values. Could you post some code how you do the subscription. – Daniel C. Weber Jan 06 '15 at 14:52

1 Answers1

2

To confirm Daniel's comment, the code as published will have at most 2 events - one from the StartWith, and possibly one from the Take(1). Check your assumptions... the output you are seeing is coming from something else other than a subscription to the posted code.

One possibility is that you are inadvertently making a new subscription to the query on each response? Pure guesswork though.

James World
  • 29,019
  • 9
  • 86
  • 120
  • Thank you. I am still trying to find the answer, but your remarks & Daniel's satisfy me that it isn't with my observable, but with subscription. – masonk Jan 07 '15 at 19:07