Skip to content

Commit 6e3af43

Browse files
committed
Add blocking to MonadError
1 parent 25fd981 commit 6e3af43

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

build.sbt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.softwaremill.SbtSoftwareMillBrowserTestJS._
2+
import com.typesafe.tools.mima.core._
23

34
val scala2_11 = "2.11.12"
45
val scala2_12 = "2.12.13"
@@ -97,7 +98,13 @@ lazy val rootProject = (project in file("."))
9798

9899
lazy val core = (projectMatrix in file("core"))
99100
.settings(
100-
name := "core"
101+
name := "core",
102+
mimaBinaryIssueFilters ++= {
103+
if (scalaVersion.value == scala2_11) {
104+
// excluding this for 2.11 as the `blocking` method will only ever be called in recompiled library code
105+
Seq(ProblemFilters.exclude[ReversedMissingMethodProblem]("sttp.monad.MonadError.blocking"))
106+
} else Nil
107+
}
101108
)
102109
.jvmPlatform(
103110
scalaVersions = scala2 ++ scala3,

core/src/main/scala/sttp/monad/MonadError.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ trait MonadError[F[_]] {
4343
}
4444

4545
def ensure[T](f: F[T], e: => F[Unit]): F[T]
46+
47+
def blocking[T](t: => T): F[T] = eval(t)
4648
}
4749

4850
trait MonadAsyncError[F[_]] extends MonadError[F] {
@@ -162,4 +164,6 @@ class FutureMonad(implicit ec: ExecutionContext) extends MonadAsyncError[Future]
162164
}
163165
p.future
164166
}
167+
168+
override def blocking[T](t: => T): Future[T] = Future(scala.concurrent.blocking(t))
165169
}

0 commit comments

Comments
 (0)