Skip to content

Refactor swap "peer finders" to use ReactiveX

NOTE: This includes the commit specified by !197 (merged).

In the old code, there is a lot of procedual style "Is this peer finder running, if so, do this". In addition, the choice to do things on background threads or not is a little ad-hoc. Finally, the SwapService needs to know about both bluetooth and wifi peer finders, whereas really they are both only there to emit "Peers", regardless of the type.

As such, some improvements in this change are:

  • The choice to run peer finding on a background thread is made once, at a higher level when starting the peer finder.
  • No longer does the UI code ask "Am I searching for peers". It instead waits to be told whether it is or isn't.
  • The addition of new types of peers in the future is the job of the Peer finder itself. It quietly aggregates all of the Peer Finders it knows about into a single observable that emits different types of peers.

This code doesn't fix any particular issue, but rather it is about making the entire swap workflow easier to reason about. I plan on migrating more of this workflow to this functional style in the future, and hopefully that will have benefits in terms of stability and code understanding.

Merge request reports