Advertisement
sanya5791

ResultUseCaseWithErrorLogging

Dec 9th, 2024 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.44 KB | None | 0 0
  1. abstract class ResultUseCaseWithErrorLogging<P, R>(
  2.     private val logEvents: Events,
  3. ) {
  4.    
  5.     operator fun invoke(params: P): Flow<Result<R>> = flow {
  6.         emit(
  7.             doWork(params)
  8.                 .onFailure { error: Throwable ->
  9.                     logEvents.exception(this::class.qualifiedName) { error }
  10.                 }
  11.         )
  12.     }
  13.  
  14.    
  15.     protected abstract suspend fun doWork(params: P): Result<R>
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement