Does WhenAny and friends always immediately 'OnNext' the current value of the properties?

StackOverflow https://stackoverflow.com/questions/22213396

  •  10-06-2023
  •  | 
  •  

Question

Within a Reactive object constructor:

    this.WhenAnyValue(x => x.SampleText, x => x)
        .Subscribe((s) => { DoSomething(s); })
        ;

The DoSomething(s) seems to get triggered immediately, actually within the call to WhenAnyValue.

This is fine -- I actually need that in this scenario because I want to feed the Observable to another object that will always require a current value. But is it something that I can count on? Is it guaranteed to happen, whether or not I'm in the constructor, or in a test runner or any other scenario?

What about the other methods: WhenAny, WhenAnyDynamic, WhenAnyObservable, ObservableForProperty? Would the same guarantee or lack of guarantee apply?

Was it helpful?

Solution

But is it something that I can count on? Is it guaranteed to happen, whether or not I'm in the constructor, or in a test runner or any other scenario?

Yep, that's part of the contract of WhenAny*, is that it fires immediately when called. ObservableForProperty does not have that guarantee.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top