Created
June 24, 2020 09:21
-
-
Save softberries/9f51d98b1025ed2040c0466cb3d37f75 to your computer and use it in GitHub Desktop.
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
def consumer(done: Deferred[IO, Unit]) = for { | |
c <- Consumer.setup | |
_ <- done.complete(()) | |
msg <- c.read | |
_ <- IO(println(s"Received $msg")) | |
} yield () | |
def producer(done: Deferred[IO, Unit]) = for { | |
p <- Producer.setup() | |
_ <- done.get | |
msg = "Msg A" | |
_ <- p.write(msg) | |
_ <- IO(println(s"Sent $msg")) | |
} yield () | |
def prog = for { | |
d <- Deferred[IO, Unit] | |
_ <- consumer(d).start | |
_ <- producer(d).start | |
} yield () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment