Skip to content

Instantly share code, notes, and snippets.

@adamw
Created June 11, 2018 18:41
Show Gist options
  • Save adamw/5b2297b9d327c894ad95f87c1d1fe863 to your computer and use it in GitHub Desktop.
Save adamw/5b2297b9d327c894ad95f87c1d1fe863 to your computer and use it in GitHub Desktop.
def broadcast(connector: QueueConnector[Task]): Task[BroadcastResult] = {
def processMessages(inbox: MVar[BroadcastMessage],
consumers: Set[String => Task[Unit]]): Task[Unit] = // ...
def consumeForever(inbox: MVar[BroadcastMessage]): Task[Unit] = // ...
for {
inbox <- MVar.empty[BroadcastMessage]
f1 <- consumeForever(inbox).fork
f2 <- processMessages(inbox, Set()).fork
} yield BroadcastResult(inbox, f1.cancel *> f2.cancel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment