Created
May 17, 2014 23:35
-
-
Save banshee/2fa9d563991dcc9bdc5b to your computer and use it in GitHub Desktop.
Topic 2
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
object TopicPlayground extends App { | |
val t: Topic[String] = scalaz.stream.async.topic() | |
val sub1 = t.subscribe | |
val out1 = sub1 | |
.flatMap(x => Process.tell(s"raw value: $x") ++ Process.emitO(x.length)) | |
.runLog | |
val otherThread = future { | |
out1.attemptRun // Added this here - now out1 is really attached to the topic | |
} | |
// Need to give out1 some time to start up. | |
// I doubt you'd do this in actual code. | |
// topics seem more useful for hooking up things like | |
// sensors that produce a continual stream of data, | |
// and where individual values can be dropped on | |
// floor. | |
Thread.sleep(100) | |
t.publishOne("foo").run // don't just call publishOne; need to run the resulting task | |
t.close.run // Don't just call close; need to run the resulting task | |
// Need to wait for the output | |
val result = Await.result(otherThread, Duration.Inf) | |
println(s"result: $result") | |
// and the output is now: result: \/-(Vector(-\/(raw value: foo), \/-(foo))) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment