Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin Coroutines: How to continue work even when children tasks fail or timeout

Wahib Ul Haq
January 28, 2019

Kotlin Coroutines: How to continue work even when children tasks fail or timeout

This talk was about sharing our learnings with the community while using Kotlin Coroutines for an interesting use case we had in our project. We are barely scratching the surface but I felt it might help others in making some better decisions with parent-child setup if they know the different uses of certain CoroutineScopes.

This talk was presented at Kotlin User Group Munich (KTUG) meetup hosted at KI labs.

Meetup link: https://www.meetup.com/Kotlin-User-Group-Munich/events/257927489/
Talk Recording: https://www.pscp.tv/w/1RDxlqmypQjKL

Wahib Ul Haq

January 28, 2019
Tweet

More Decks by Wahib Ul Haq

Other Decks in Technology

Transcript

  1. Event A Event B Event C Event D Computation Computation

    Computation Time Taken Certain Limit
  2. This scope waits for the completion of all its children

    and in case of a crash the scope cancels all children.
  3. Child’s failure is not propagated to the parent. Hence, every

    child should handle its exception by itself. Difference #2
  4. Use Coroutine Scope if you want your parent job to

    fail if one of the children fails
  5. Use Coroutine Scope if you want your parent job to

    fail if one of the children fails Use Supervision Scope if you want your parent job to complete in case of failure of one or more of children jobs
  6. Use Coroutine Scope if you want your parent job to

    fail if one of the children fails Use Supervision Scope if you want your parent job to complete in case of failure of one or more of children jobs CoroutineExceptionHandler can be used to replace try /catch blocks and handle exceptions in a centralised and cleaner way
  7. Use Coroutine Scope if you want your parent job to

    fail if one of the children fails Use Supervision Scope if you want your parent job to complete in case of failure of one or more of children jobs CoroutineExceptionHandler can be used to replace try /catch blocks and handle exceptions in a centralised and cleaner way InvokeOnInvocation() can be used to react to changes like when parent job completes (gracefully or not) or Timeout Cancellation happens