5

I use suspend function in Pagging Library Jetpack.

in loadAfter() and loadInitial() I use retrofit suspending functions. For this I need to use GlobalScope which is not recomended, How I can pass viewModel's scope?

Nurseyit Tursunkulov
  • 8,012
  • 12
  • 44
  • 78

1 Answers1

1

My solution is usually that I make functions that call suspending functions also suspending and only do calls like viewModelScope.launch(Dispatchers.IO) in the ViewModel that asks for the data. This way the suspend keyword spreads a bit through the application, but I also have the control of stopping such background operations on the UI level, where I can cancel the request if the data is no longer required because the user switched the view.

findusl
  • 2,454
  • 8
  • 32
  • 51