wealthfront/magellan

Consider making navigation asynchronous

ryanmoelter opened this issue · 0 comments

Background

Navigation, as it stands today, has a few weird edge cases.

  • What happens if you navigate before navigation is finished, e.g. in onShow()? Currently magellan breaks in non-obvious ways ("Cannot pause() from a state that is not Resumed: MyStep is Shown").
  • Navigating from the previous Step's shownScope causes the scope we're operating in to be disposed before the navigation is done. This has caused problems with Rx in the past, and will probably cause problems with coroutines in the future.

Acceptance criteria

  • Navigation is done in the navigator's Created coroutine scope
  • Navigator uses a messageQueue, and any navigation started during another navigation event is postponed until the current navigation event is done.

Misc thoughts and unsolved questions

  • Should navigate be a suspending function or return immediately?
    • Case: Navigation is started in Step (scoped or no)
      • Suspending function doesn't make sense, since the scope will be disposed halfway through the navigation event
      • Return immediately makes sense
    • Case: Navigation is started in Journey (scoped or no)
      • Could be helpful to know when the navigation event ends, so we can e.g. update state machine accordingly
      • Return immediately could make sense for simple cases
  • Should navigation be run on the main thread?
    • It's probably technically better to run it on a background thread, but might not be worth the complexity
  • We probably shouldn't make navigation blocking anymore (non-suspending), since it would only sometimes be able to do so.