en

Mark Murphy

  • b4777467766has quoted2 years ago
    Flows do not wind up on some other dispatcher by magic. Instead, they use the same dispatcher mechanism as we use for the rest of coroutines.
  • b4777467766has quoted2 years ago
    Another option is to use flowOn() to customize the Flow
  • b4777467766has quoted2 years ago
    Now, the lambda expression will run on Dispatchers.Default, but our collection of the results will be performed on Dispatchers.Main (courtesy of the launch() dispatcher).
  • b4777467766has quoted2 years ago
    onStart(), allows you to inject new values before the “real” content emitted by the Flow:
  • b4777467766has quoted2 years ago
    Anything you emit() from onStart() will be emitted by the Flow first.
  • b4777467766has quoted2 years ago
    The default behavior of Flow mirrors what happens with a suspend function that throws an exception: you can just catch it
  • b4777467766has quoted2 years ago
    The collect() call will throw the exception raised by the Flow, and you can use an ordinary try/catch structure to handle it.
  • b4777467766has quoted2 years ago
    Sometimes, though, we want to retry the work being done by the Flow in case of an exception. For example, with network I/O, some exceptions represent random failures, such as the user of a mobile device switching from WiFi to mobile data mid-way through a download.
  • b4777467766has quoted2 years ago
    retry(N), for a given value of N, will just blindly retry the Flow that number of times. If it continues to fail after the N tries, then the exception proceeds normally
  • b4777467766has quoted2 years ago
    You can optionally pass a lambda expression to retry(). This receives the exception as a parameter. Now the exception will continue to the FlowCollector if either:

    We have exceeded the maximum number of retries, or
    The lambda expression returns false
fb2epub
Drag & drop your files (not more than 5 at once)