每次方法调用时可观察到的新数据
这对于那些熟悉技术的人来说可能非常简单,但是每当调用我的方法时,我如何直接向给定的可观察对象提供新数据?
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()));
}
我也不知道我应该使用哪种可观察的,仅在特殊情况下才能到达 OnCompleted() 的观察?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是基本答案。我稍微修改了你的代码。
这应该有效。主题只是一个 IObservable 和一个 IObserver。您可以调用 OnCompleted、OnError 等。
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.
我测试并得到了这个工作:
I tested and got this working: