mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Properly initialize thread pools
This commit is contained in:
@ -2,6 +2,8 @@ package docspell.common
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import java.util.concurrent.{Executors, ThreadFactory}
|
||||
import cats.effect._
|
||||
import scala.concurrent._
|
||||
|
||||
object ThreadFactories {
|
||||
|
||||
@ -17,4 +19,16 @@ object ThreadFactories {
|
||||
}
|
||||
}
|
||||
|
||||
def executorResource[F[_]: Sync](
|
||||
c: => ExecutionContextExecutorService
|
||||
): Resource[F, ExecutionContextExecutorService] =
|
||||
Resource.make(Sync[F].delay(c))(ec => Sync[F].delay(ec.shutdown))
|
||||
|
||||
def cached[F[_]: Sync](tf: ThreadFactory): Resource[F, ExecutionContextExecutorService] =
|
||||
executorResource(
|
||||
ExecutionContext.fromExecutorService(Executors.newCachedThreadPool(tf))
|
||||
)
|
||||
|
||||
def fixed[F[_]: Sync](n: Int, tf: ThreadFactory): Resource[F, ExecutionContextExecutorService] =
|
||||
executorResource(ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(n, tf)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user