diff --git a/src/main/kotlin/me/misik/api/app/GetReviewFacade.kt b/src/main/kotlin/me/misik/api/app/GetReviewFacade.kt index 47c7812..d9bdcb8 100644 --- a/src/main/kotlin/me/misik/api/app/GetReviewFacade.kt +++ b/src/main/kotlin/me/misik/api/app/GetReviewFacade.kt @@ -1,5 +1,6 @@ package me.misik.api.app +import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeout import me.misik.api.core.GracefulShutdownDispatcher @@ -16,8 +17,17 @@ class GetReviewFacade( fun getReview(id: Long): Review { return runBlocking(GracefulShutdownDispatcher.dispatcher) { withTimeout(60.seconds) { - reviewService.getReview(id) - }.get() + var result: Review? = null + while (result == null) { + delay(500) + reviewService.getById(id) + .takeIf { it.isCompleted } + .let { + result = it + } + } + return@withTimeout result!! + } } } } diff --git a/src/main/kotlin/me/misik/api/domain/ReviewService.kt b/src/main/kotlin/me/misik/api/domain/ReviewService.kt index 41517d8..392809b 100644 --- a/src/main/kotlin/me/misik/api/domain/ReviewService.kt +++ b/src/main/kotlin/me/misik/api/domain/ReviewService.kt @@ -46,7 +46,4 @@ class ReviewService( fun getById(id: Long): Review = reviewRepository.findByIdOrNull(id) ?: throw IllegalArgumentException("Cannot find review by id \"$id\"") - - fun getReview(id: Long) = reviewRepository.findById(id) - ?: throw IllegalArgumentException("Cannot find review by id \"$id\"") }