this may be really simple to those in the know-how, but how can i directly provide new data to a given observable, whenever a method of mine is invoked?
IObservable<int> _myObservable;
void ThingsCallMe(int someImportantNumber)
{
// Current pseudo-code seeking to be replaced with something that would compile?
_myObservable.Add(someImportantNumber);
}
void ISpyOnThings()
{
_myObservable.Subscribe(
i =>
Console.WriteLine("stole your number " + i.ToString()));
}
i also dont know what kind of observable i should employ, one that gets to OnCompleted() under special circumstances only?
Here’s the basic answer. I modified your code slightly.
This should work. A subject is simply an IObservable and an IObserver. You can call OnCompleted, OnError, etc.