Skip to content
Permalink
Browse files

Change syntax to `compile.resource`

  • Loading branch information...
SystemFw committed Jan 25, 2019
1 parent 8425855 commit 3165714a9874acd3d4b041ea03c51433f024c31c
@@ -6,7 +6,7 @@ import cats.effect.concurrent.{Deferred, Ref}
import scala.concurrent.duration._

class ResourceCompilationSpec extends AsyncFs2Spec {
"compile.toResource - concurrently" in {
"compile.resource - concurrently" in {
val prog: Resource[IO, IO[Unit]] =
Stream
.eval(Deferred[IO, Unit].product(Deferred[IO, Unit]))
@@ -18,13 +18,13 @@ class ResourceCompilationSpec extends AsyncFs2Spec {
Stream.emit(result).concurrently(worker)
}
.compile
.toResource
.resource
.lastOrError

prog.use(x => x).timeout(5.seconds).unsafeToFuture
}

"compile.toResource - onFinalise" in {
"compile.resource - onFinalise" in {
val expected = List(
"stream - start",
"stream - done",
@@ -60,7 +60,7 @@ class ResourceCompilationSpec extends AsyncFs2Spec {
.emit("resource - start")
.onFinalize(record("resource - done"))
.compile
.toResource
.resource
.lastOrError
.use(x => record(x))

@@ -70,15 +70,15 @@ class ResourceCompilationSpec extends AsyncFs2Spec {
.map(_ shouldBe expected)
}

"compile.toResource - allocated" in {
"compile.resource - allocated" in {
Ref[IO]
.of(false)
.flatMap { written =>
Stream
.emit(())
.onFinalize(written.set(true))
.compile
.toResource
.resource
.lastOrError
.allocated >> written.get
}
@@ -92,5 +92,5 @@ object ResourceCompilationSpec {
/** This should compile */
val pure: List[Int] = Stream.range(0, 5).compile.toList
val io: IO[List[Int]] = Stream.range(0, 5).covary[IO].compile.toList
val resource: Resource[IO, List[Int]] = Stream.range(0, 5).covary[IO].compile.toResource.toList
val resource: Resource[IO, List[Int]] = Stream.range(0, 5).covary[IO].compile.resource.toList
}
@@ -3711,8 +3711,7 @@ object Stream extends StreamLowPriority {
}

object Compiler extends LowPrioCompiler {
// TOOD make this private once the Resource compiler is properly implemented
private[Stream] def compile[F[_], O, B](stream: FreeC[Algebra[F, O, ?], Unit], init: B)(
private def compile[F[_], O, B](stream: FreeC[Algebra[F, O, ?], Unit], init: B)(
f: (B, Chunk[O]) => B)(implicit F: Sync[F]): F[B] =
F.bracketCase(CompileScope.newRoot[F])(scope =>
Algebra.compile[F, O, B](stream, scope, init)(f))((scope, ec) => scope.close(ec).rethrow)
@@ -3912,7 +3911,7 @@ object Stream extends StreamLowPriority {
to[List]

/** TODO scaladoc **/
def toResource(implicit compiler: Stream.Compiler[G, Resource[G, ?]])
def resource(implicit compiler: Stream.Compiler[G, Resource[G, ?]])
: Stream.CompileOps[G, Resource[G, ?], O] =
new Stream.CompileOps[G, Resource[G, ?], O](free)

0 comments on commit 3165714

Please sign in to comment.
You can’t perform that action at this time.