Understood using Rx Extensions but what is PUSH model in this?
This is my code which monitors mouse moves after mouseleftbuttondown and till mouseleftbuttonup:
var downs = Observable.FromEventPattern<MouseEventArgs>(this, "MouseLeftButtonDown");
var ups = Observable.FromEventPattern<MouseEventArgs>(this, "MouseLeftButtonUp");
var moves = Observable.FromEventPattern<MouseEventArgs>(this, "MouseMove").SkipUntil(downs).TakeUntil(ups).Repeat();
moves.Subscribe(me => {
Point pt = me.EventArgs.GetPosition(null);
tbPoints.Text += "X :" + pt.X + " Y :开发者_如何学编程" + pt.Y + "\t";
});
All works out well but what I don't understand here is what is PUSH in this? I read IEnumerable follows PULL pattern and IObservable follows PUSH model. What exactly is push in this?
Events are PUSH in this code. All the various mouse events you have converted to observable pushes the event data to your code whenever that event happens.
When some data source tells the consumer of the data that here is more data for you to process thats the PUSH model, when you ask the data source for data thats the pull mode. Events are first class example of PUSH model.
After the Subscribe method your next line of code will start executing, because using Subscribe you have asked the PUSH data source to tell your code whenever some data (in this case mouse event) is available (which will happen in future, so subscribe doesn't block)
精彩评论