Created
December 20, 2017 09:12
-
-
Save n4to4/13c98319dad672165728baa8c59d85b1 to your computer and use it in GitHub Desktop.
fs2practice.scala
This file contains hidden or 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 Main extends App { | |
import cats.effect.IO | |
import fs2.{Stream, Sink} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val count = new java.util.concurrent.atomic.AtomicLong(0) | |
val acquire = IO { println("incremented: " + count.incrementAndGet); () } | |
val release = IO { println("decremented: " + count.decrementAndGet); () } | |
val err = Stream.raiseError(new Exception("oh noes!")) | |
val s = | |
Stream.range(1, 10) | |
.repeat | |
.take(19) | |
.segmentN(5) | |
val z = | |
Stream.bracket(acquire)(_ => s /*++ err*/, _ => release) | |
.observe(Sink(x => IO(println("x => " + x.force.toList)))) | |
println(z.runLog.unsafeRunSync) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment