Created
January 31, 2017 04:37
-
-
Save gvolpe/9a6b11f81d60aa09ec131b4aaac98a00 to your computer and use it in GitHub Desktop.
Different behavior between Q.enqueue1 and Q.enqueue when calling Q.dequeue
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
package com.gvolpe.fs2queue | |
import fs2.{Stream, Task, async} | |
object FS2QueueBehavior extends App { | |
implicit val S = fs2.Strategy.fromFixedDaemonPool(2, "fs2-queue") | |
val p1 = for { | |
simpleQ <- Stream.eval(async.boundedQueue[Task, String](10)) | |
_ <- Stream.emits[Task, String](Seq("This is fs2!", "Hello", "World!")) to simpleQ.enqueue | |
// _ <- Stream("This is fs2!", "Hello", "World!") to simpleQ.enqueue | |
result <- simpleQ.dequeue.take(3) | |
} yield { | |
println(result) | |
} | |
// p1.run.unsafeRun() | |
val p2 = for { | |
simpleQ <- Stream.eval(async.boundedQueue[Task, String](10)) | |
_ <- Stream.eval(simpleQ.enqueue1("Hello")) | |
_ <- Stream.eval(simpleQ.enqueue1("World!")) | |
_ <- Stream.eval(simpleQ.enqueue1("This is fs2!")) | |
result <- simpleQ.dequeue.take(3) | |
} yield { | |
println(result) | |
} | |
p2.run.unsafeRun() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment