0

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?

Clyde
  • 8,017
  • 11
  • 56
  • 87

1 Answers1

2

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.

Ana Betts
  • 73,868
  • 16
  • 141
  • 209