Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push vs pull in reactive-banana

I am building a mediaplayer-like application using reactive-banana.

Let's say I want a Behavior that represents the currently selected track in the track list.

I have two options: use fromPoll to get the current selection when it's needed; or use fromChanges and subscribe to the selection change event.

I use the selected track Behavior only when the user presses the "Play" button. This event is much more rare than a selection change.

Given that, I'd assume that fromPoll would be better/more efficient than fromChanges in this situation. But the docs say that "the recommended way to obtain Behaviors is by using fromChanges".

Does it still apply here? I.e. will the polling action be executed more often than it is actually used (sampled) by the network?

like image 240
Roman Cheplyaka Avatar asked Jun 11 '13 19:06

Roman Cheplyaka


1 Answers

In the current version (0.7) of reactive-banana, the fromPoll function actually creates a behavior whose value is determined by executing the polling action whenever any event happens at all.

In contrast, fromChanges will only update the behavior when the particular event given as argument has an occurrence.

In other words, in the current implementation, fromPoll is always less efficient than fromChanges.

Then again, I wouldn't worry too much about efficiency right now, because I haven't spent much time implementing suitable optimizations yet. Just use whatever is simplest now and save any efficiency issues for future versions of reactive-banana.

like image 86
Heinrich Apfelmus Avatar answered Sep 27 '22 21:09

Heinrich Apfelmus