File tree 2 files changed +12
-5
lines changed
src/main/kotlin/me/misik/api
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 1
1
package me.misik.api.app
2
2
3
+ import kotlinx.coroutines.delay
3
4
import kotlinx.coroutines.runBlocking
4
5
import kotlinx.coroutines.withTimeout
5
6
import me.misik.api.core.GracefulShutdownDispatcher
@@ -16,8 +17,17 @@ class GetReviewFacade(
16
17
fun getReview (id : Long ): Review {
17
18
return runBlocking(GracefulShutdownDispatcher .dispatcher) {
18
19
withTimeout(60 .seconds) {
19
- reviewService.getReview(id)
20
- }.get()
20
+ var result: Review ? = null
21
+ while (result == null ) {
22
+ delay(500 )
23
+ reviewService.getById(id)
24
+ .takeIf { it.isCompleted }
25
+ .let {
26
+ result = it
27
+ }
28
+ }
29
+ return @withTimeout result!!
30
+ }
21
31
}
22
32
}
23
33
}
Original file line number Diff line number Diff line change @@ -46,7 +46,4 @@ class ReviewService(
46
46
47
47
fun getById (id : Long ): Review = reviewRepository.findByIdOrNull(id)
48
48
? : throw IllegalArgumentException (" Cannot find review by id \" $id \" " )
49
-
50
- fun getReview (id : Long ) = reviewRepository.findById(id)
51
- ? : throw IllegalArgumentException (" Cannot find review by id \" $id \" " )
52
49
}
You can’t perform that action at this time.
0 commit comments