Last active
August 29, 2015 14:26
-
-
Save taisukeoe/6a51ad5def95068e00c6 to your computer and use it in GitHub Desktop.
scalaz-streamsのTask.startは、既存のTaskの実行Threadも変更できそう
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 streams._ | |
import util._ | |
implicit val s = Strategy.fromExecutionContext(scala.concurrent.ExecutionContext.Implicits.global) | |
val t = Task(println(Thread.currentThread.getName)) | |
// Exiting paste mode, now interpreting. | |
import streams._ | |
import util._ | |
s: streams.util.Strategy = streams.util.Strategy$$anon$1@60d8175 | |
t: streams.Task[Unit] = streams.Task@60ae2b6d | |
scala> for{ | |
| t1 <- t | |
| t2 <- Task.start(t)(Strategy.sequential) | |
| t3 <- t2 | |
| } yield {Unit} | |
res0: streams.Task[Unit.type] = streams.Task@4bb621c | |
scala> res0.run | |
ForkJoinPool-1-worker-13 | |
ForkJoinPool-1-worker-11 | |
res1: Unit.type = object scala.Unit | |
scala> Task(println(Thread.currentThread.getName))(Strategy.sequential).run | |
run-main-0 |
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
scala> import streams._ | |
import streams._ | |
scala> import util._ | |
import util._ | |
scala> implicit val s = Strategy.fromExecutionContext(scala.concurrent.ExecutionContext.Implicits.global) | |
s: streams.util.Strategy = streams.util.Strategy$$anon$1@785eb11 | |
scala> val t = Task(println(Thread.currentThread.getName)) | |
t: streams.Task[Unit] = streams.Task@77de626 | |
scala> t.run | |
ForkJoinPool-1-worker-13 | |
scala> for{ | |
| t1 <- t | |
| t2 <- Task.start(t) | |
| t3 <- t2 | |
| } yield {(t1,t3)} | |
res1: streams.Task[(Unit, Unit)] = streams.Task@5509b26b | |
scala> res1.run | |
ForkJoinPool-1-worker-13 | |
ForkJoinPool-1-worker-11 | |
res2: (Unit, Unit) = ((),()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment