{ val local = async { // no parent localShowStore.getShow(showId) } val remote = async [ // no parent remoteSource.getShow(showId) ] val merged = mergeShow(local.await(), remote.await()) localShowStore.saveShow(merged) } 16
= async { // will be cancelled on job.cancel() localShowStore.getShow(showId) } val remote = async [ // will be cancelled on job.cancel() remoteSource.getShow(showId) ] val merged = mergeShow(local.await(), remote.await()) localShowStore.saveShow(merged) } 19
Muntenescu • Why using coroutines • Where to using coroutines • How to using coroutines • Java • Type Safety - Inner class (Kotlin 1.3) 6 https://youtu.be/Sy6ZdgqrQp0 25
(Runtime overhead) • Primitive types are heavily optimized by the runtime inline class StoryId(val id: Long) • From Kotlin 1.3 • An inline class must have a single property initialized in the primary constructor 37
single responsibility • UseCase should have only one public method class PostStoryCommentUseCase(repository: XXXRepository) { suspend fun postStoryComment(body: String, id: Long): Result<Comment> } 38
this is implemented, even nor method name class PostStoryComment(...) { suspend operator fun invoke(body: String, id: Long): Result<Comment> } // Caller side val postStoryComment = ... val result = postStoryComment(comment, id) 39