Skip to content

Instantly share code, notes, and snippets.

@shajra
Created February 28, 2016 23:30
Show Gist options
  • Save shajra/12e162353d06e9145196 to your computer and use it in GitHub Desktop.
Save shajra/12e162353d06e9145196 to your computer and use it in GitHub Desktop.
using phantom types to keep track of thread pool types carefully
import java.util.concurrent.ExecutorService
import scalaz.Maybe
import scalaz.syntax.maybe._
final case class Pools(cpu: Maybe[Pool[Pool.Cpu]], io: Maybe[Pool[Pool.Io]])
object Pools {
def none: Pools = Pools(Maybe.empty, Maybe.empty)
def both(io: Pool[Pool.Io], cpu: Pool[Pool.Cpu]) = Pools(cpu.just, io.just)
}
final class Pool[A] private (private[kafka] val service: ExecutorService)
object Pool {
trait Cpu
trait Io
def io(service: ExecutorService): Pool[Io] = new Pool(service)
def cp(service: ExecutorService): Pool[Cpu] = new Pool(service)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment