Skip to content

Conversation

@hifeful
Copy link
Owner

@hifeful hifeful commented Jun 28, 2023

  • MyMealsFragment.kt was reimplemented to use custom MVI with Flows instead of MVICore's solution
  • Coroutines were added
  • Other small fixes

…nstead of MVICore's solution

- Coroutines were added
- Other small fixes
binding.bind(it, recentMealsAdapter, favouriteMealsAdapter)
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct ✅
Just FYI: there is the alternative of Flow.flowWithLifecycle

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 No action required

when (event) {
is MyMealsEvent.LoadRecentMeals -> mealsRepository.getRecentMeals()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we have Rx and Coroutines together, we should convert Rx into Coroutine.
That way, we gonna have control of threads and easily debug and handle any errors.
👌 The known and checked solution of how to do this conversion is using suspendCoroutine:

suspendCoroutine { continuation ->
    try {
          continuation.resume(mealsRepository.getRecentMeals().blockingGet())
    } catch (cancellation: CancellationException) {
          continuation.resumeWithException(cancellation)
    } catch (failure: Exception) {
          // handle error somehow (for instance, map to custom error type)
          continuation.resumeWithException(cancellation)
    }
 }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No action is required for now
As threading will be in another module soon

@lus-ence lus-ence mentioned this pull request Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants