Skip to content

Instantly share code, notes, and snippets.

@gvolpe
Created January 31, 2017 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvolpe/9a6b11f81d60aa09ec131b4aaac98a00 to your computer and use it in GitHub Desktop.
Save gvolpe/9a6b11f81d60aa09ec131b4aaac98a00 to your computer and use it in GitHub Desktop.
Different behavior between Q.enqueue1 and Q.enqueue when calling Q.dequeue
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