Created
February 28, 2016 23:30
-
-
Save shajra/12e162353d06e9145196 to your computer and use it in GitHub Desktop.
using phantom types to keep track of thread pool types carefully
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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