-
Blocking Futurescala/basic 2023. 2. 13. 11:16
scala-best-practices 의 MUST use Scala's BlockContext on blocking I/O 문서와 SHOULD use a separate thread-pool for blocking I/O 를 참고했을 때, 간편하게 쓴다면 아래처럼 BlockingFuture Helper 를 만드는 것도 좋을 것 같다.
import scala.concurrent.{blocking, Future, ExecutionContext} /** * This is an idiomatic way of executing blocking code * Use BlockingFuture(...) instead of normal Future(...) anywhere */ object BlockingFuture { def apply[T](body: => T)(implicit execctx: ExecutionContext): Future[T] = Future { blocking { body } } }
'scala > basic' 카테고리의 다른 글
Tagless Final (0) 2024.11.19 method 이름은 같은데 param, return 타입을 다르게 구현하기 (0) 2024.03.07 Environment, Property variable 읽기 (0) 2023.02.03 Future[Try[A]] <=> Future[A] 상호간 변환하기 (0) 2023.01.16 Error Modeling (with Exception) (0) 2023.01.16