Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit 0196ab3

Browse files
authored
Merge pull request #74 from reactor/Removing_cats_effect
Removing cats-effect which was effectively was only to get ExitCase.
2 parents 799b614 + 67fca90 commit 0196ab3

File tree

8 files changed

+35
-33
lines changed

8 files changed

+35
-33
lines changed

build.sbt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ val mockitoInline = "org.mockito" % "mockito-inline" % "3.3.3" % "test"
88
val mockitoScala = "org.mockito" %% "mockito-scala" % "1.14.3" % "test"
99
val scalaTest = "org.scalatest" %% "scalatest" % "3.1.2" % "test"
1010
val reactorTest = "io.projectreactor" % "reactor-test" % reactorVersion % "test"
11-
val catsEffect = "org.typelevel" %% "cats-effect" % "2.1.3"
1211

1312
//Scala versions for cross compiling
1413
lazy val scala212 = "2.12.11"
@@ -26,8 +25,7 @@ lazy val root = (project in file("."))
2625
libraryDependencies += mockitoScala,
2726
libraryDependencies += scalaTest,
2827
libraryDependencies += reactorTest,
29-
libraryDependencies += mockitoInline,
30-
libraryDependencies += catsEffect
28+
libraryDependencies += mockitoInline
3129
)
3230

3331
// Prevent test being executed in parallel as it may failed for the Scheduler and Virtual Scheduler
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package reactor.core.scala.publisher
2+
3+
trait ExitCondition
4+
5+
case object Completed extends ExitCondition
6+
7+
case object Cancelled extends ExitCondition
8+
9+
case class Error(ex: Throwable) extends ExitCondition

src/main/scala/reactor/core/scala/publisher/SFluxLike.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package reactor.core.scala.publisher
33
import java.util.concurrent.TimeUnit
44
import java.util.function.Function
55

6-
import cats.effect.ExitCase
76
import org.reactivestreams.{Publisher, Subscription}
87
import reactor.core.publisher.{Flux => JFlux}
98
import reactor.core.scheduler.Schedulers
@@ -14,14 +13,14 @@ import scala.util.{Failure, Success, Try}
1413

1514
trait SFluxLike[+T] extends ScalaConverters { self: SFlux[T] =>
1615

17-
final def bracket[R](use: T => SFlux[R])(release: T => Unit): SFlux[R] = bracketCase(use)((t, _) => release(t))
16+
final def using[R](use: T => SFlux[R])(release: T => Unit): SFlux[R] = usingWhen(use)((t, _) => release(t))
1817

19-
final def bracketCase[R](use: T => SFlux[R])(release: (T, ExitCase[Throwable]) => Unit): SFlux[R] = {
18+
final def usingWhen[R](use: T => SFlux[R])(release: (T, ExitCondition) => Unit): SFlux[R] = {
2019
val f = (t: T) => (Try(use(t)) match {
21-
case Success(value) => value.doOnComplete(() => release(t, ExitCase.Completed))
20+
case Success(value) => value.doOnComplete(() => release(t, Completed))
2221
case Failure(exception) => SFlux.error(exception)
23-
}).doOnError(ex => release(t, ExitCase.error(ex)))
24-
.doOnCancel(() => release(t, ExitCase.canceled))
22+
}).doOnError(ex => release(t, Error(ex)))
23+
.doOnCancel(() => release(t, Cancelled))
2524
concatMap(f)
2625
}
2726

src/main/scala/reactor/core/scala/publisher/SMonoLike.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package reactor.core.scala.publisher
22

3-
import cats.effect.ExitCase
4-
import cats.effect.ExitCase.{Canceled, Completed}
53
import org.reactivestreams.Publisher
64
import reactor.core.publisher.{Mono => JMono}
75

@@ -12,14 +10,14 @@ trait SMonoLike[+T] extends ScalaConverters { self: SMono[T] =>
1210

1311
private[publisher] def coreMono: JMono[_ <: T]
1412

15-
final def bracket[R](use: T => SMono[R])(release: T => Unit): SMono[R] = bracketCase(use)((t, _) => release(t))
13+
final def using[R](use: T => SMono[R])(release: T => Unit): SMono[R] = usingWhen(use)((t, _) => release(t))
1614

17-
final def bracketCase[R](use: T => SMono[R])(release: (T, ExitCase[Throwable]) => Unit): SMono[R] = {
15+
final def usingWhen[R](use: T => SMono[R])(release: (T, ExitCondition) => Unit): SMono[R] = {
1816
val f: T => SMono[R] = (t: T) => (Try(use(t)) match {
1917
case Success(value) => value.doOnSuccess(_ => release(t, Completed))
2018
case Failure(exception) => SMono.error(exception)
21-
}).doOnError(ex => release(t, ExitCase.error(ex)))
22-
.doOnCancel(() => release(t, Canceled))
19+
}).doOnError(ex => release(t, Error(ex)))
20+
.doOnCancel(() => release(t, Cancelled))
2321
flatMap(f)
2422
}
2523

src/test/scala-2.12/reactor/core/scala/publisher/SFlux212Test.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SFlux212Test extends AnyFreeSpec with Matchers {
5757
.verifyComplete()
5858
}
5959
}
60-
"bracketCase" - {
60+
"usingWhen" - {
6161
"should release all resources properly" in {
6262
import java.io.PrintWriter
6363
val files = (0 until 5) map(i => {
@@ -68,9 +68,9 @@ class SFlux212Test extends AnyFreeSpec with Matchers {
6868
})
6969
files.foreach(f => f.exists() shouldBe true)
7070
val sf = SFlux.fromIterable(files)
71-
.bracketCase(f => {
71+
.usingWhen(f => {
7272
SFlux.just(Source.fromFile(f))
73-
.bracket(br => SFlux.fromIterable(br.getLines().toIterable))(_.close())
73+
.using(br => SFlux.fromIterable(br.getLines().toIterable))(_.close())
7474
})((file, _) => file.delete())
7575
StepVerifier.create(sf)
7676
.expectNext("0", "1", "2", "3", "4")

src/test/scala-2.13/reactor/core/scala/publisher/SFlux213Test.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SFlux213Test extends AnyFreeSpec with Matchers {
6565
}
6666
}
6767

68-
".bracketCase" - {
68+
".usingWhen" - {
6969
"should release all resources properly" in {
7070
import java.io.PrintWriter
7171
val files = (0 until 5) map(i => {
@@ -76,9 +76,9 @@ class SFlux213Test extends AnyFreeSpec with Matchers {
7676
})
7777
files.foreach(f => f.exists() shouldBe true)
7878
val sf = SFlux.fromIterable(files)
79-
.bracketCase(f => {
79+
.usingWhen(f => {
8080
SFlux.just(Source.fromFile(f))
81-
.bracket(br => SFlux.fromIterable(br.getLines().iterator.to(Iterable)))(_.close())
81+
.using(br => SFlux.fromIterable(br.getLines().iterator.to(Iterable)))(_.close())
8282
})((file, _) => file.delete())
8383
StepVerifier.create(sf)
8484
.expectNext("0", "1", "2", "3", "4")

src/test/scala/reactor/core/scala/publisher/SFluxTest.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import java.util.concurrent.Callable
88
import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger, AtomicLong, AtomicReference}
99
import java.util.function.Consumer
1010

11-
import cats.effect.ExitCase.Error
1211
import io.micrometer.core.instrument.Metrics
1312
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
1413
import org.mockito.{ArgumentMatchersSugar, IdiomaticMockito}
@@ -524,7 +523,7 @@ class SFluxTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChecks
524523
}
525524
}
526525

527-
".bracket should always release all resources properly" in {
526+
".using should always release all resources properly" in {
528527
import java.io.PrintWriter
529528
val files = (0 until 1) map(i => {
530529
val path = Files.createTempFile(s"bracketCase-$i", ".tmp")
@@ -534,15 +533,15 @@ class SFluxTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChecks
534533
})
535534
files.foreach(f => f.exists() shouldBe true)
536535
val sf = SFlux.fromIterable(files)
537-
.bracket(_ => SFlux.error(new RuntimeException("Always throw exception")))(file => file.delete())
536+
.using(_ => SFlux.error(new RuntimeException("Always throw exception")))(file => file.delete())
538537
StepVerifier.create(sf)
539538
.expectError(classOf[RuntimeException])
540539
.verify()
541540
files.foreach(f => f.exists() shouldBe false)
542541
}
543542

544-
".bracketCase" - {
545-
"should handle ExitCase.error" - {
543+
".usingWhen" - {
544+
"should handle ExitCondition error" - {
546545
"when the error happens inside the generated flux" in {
547546
import java.io.PrintWriter
548547
val files = (0 until 5) map(i => {
@@ -554,7 +553,7 @@ class SFluxTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChecks
554553
try {
555554
files.foreach(f => f.exists() shouldBe true)
556555
val sf = SFlux.fromIterable(files)
557-
.bracketCase(_ => {
556+
.usingWhen(_ => {
558557
SFlux.error(new RuntimeException("Always throw exception"))
559558
})((file, exitCase) => {
560559
exitCase match {
@@ -582,7 +581,7 @@ class SFluxTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChecks
582581
try {
583582
files.foreach(f => f.exists() shouldBe true)
584583
val sf = SFlux.fromIterable(files)
585-
.bracketCase(_ => throw new RuntimeException)((file, exitCase) => {
584+
.usingWhen(_ => throw new RuntimeException)((file, exitCase) => {
586585
exitCase match {
587586
case Error(_) => ()
588587
case _ => file.delete()

src/test/scala/reactor/core/scala/publisher/SMonoTest.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import java.util.concurrent._
55
import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger, AtomicLong, AtomicReference}
66
import java.util.function.Supplier
77

8-
import cats.effect.ExitCase.Error
98
import io.micrometer.core.instrument.Metrics
109
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
1110
import org.mockito.{ArgumentMatchersSugar, IdiomaticMockito}
@@ -426,7 +425,7 @@ class SMonoTest extends AnyFreeSpec with Matchers with TestSupport with Idiomati
426425

427426
file.exists() shouldBe true
428427
val sMono = SMono.just(file)
429-
.bracket(_ => SMono.error(new RuntimeException("Always throw exception")))(file => file.delete())
428+
.using(_ => SMono.error(new RuntimeException("Always throw exception")))(file => file.delete())
430429
StepVerifier.create(sMono)
431430
.expectError(classOf[RuntimeException])
432431
.verify()
@@ -442,7 +441,7 @@ class SMonoTest extends AnyFreeSpec with Matchers with TestSupport with Idiomati
442441

443442
file.exists() shouldBe true
444443
val sMono = SMono.just(file)
445-
.bracketCase(f => {
444+
.usingWhen(f => {
446445
val br = Source.fromFile(f)
447446
val line = br.getLines().mkString
448447
br.close()
@@ -464,7 +463,7 @@ class SMonoTest extends AnyFreeSpec with Matchers with TestSupport with Idiomati
464463
try {
465464
file.exists() shouldBe true
466465
val sMono = SMono.just(file)
467-
.bracketCase(_ => {
466+
.usingWhen(_ => {
468467
SMono.error(new RuntimeException("Always throw exception"))
469468
})((file, exitCase) => {
470469
exitCase match {
@@ -488,7 +487,7 @@ class SMonoTest extends AnyFreeSpec with Matchers with TestSupport with Idiomati
488487
try {
489488
file.exists() shouldBe true
490489
val sMono = SMono.just(file)
491-
.bracketCase(_ => throw new RuntimeException)((file, exitCase) => {
490+
.usingWhen(_ => throw new RuntimeException)((file, exitCase) => {
492491
exitCase match {
493492
case Error(_) => ()
494493
case _ => file.delete()

0 commit comments

Comments
 (0)