All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.evolutiongaming.kafka.journal.execution.ScheduledExecutorServiceOf.scala Maven / Gradle / Ivy

The newest version!
package com.evolutiongaming.kafka.journal.execution

import java.util.concurrent.{ScheduledExecutorService, ThreadFactory, Executors => ExecutorsJ}

import cats.effect.{Resource, Sync}
import cats.syntax.all._


object ScheduledExecutorServiceOf {

  def apply[F[_] : Sync](
    parallelism: Int,
    threadFactory: ThreadFactory
  ): Resource[F, ScheduledExecutorService] = {

    val result = for {
      threadPool <- Sync[F].delay { ExecutorsJ.newScheduledThreadPool(parallelism, threadFactory) }
    } yield {
      val release = Sync[F].delay { threadPool.shutdown() }
      (threadPool, release)
    }
    Resource(result)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy