Skip to content

Commit

Permalink
Merge pull request #3304 from kamilkloch/syntax-all
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak authored Dec 5, 2022
2 parents 9f1c1c9 + 29613bc commit 52b5a3b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import cats.data.Ior
import cats.effect.instances.spawn
import cats.effect.kernel.CancelScope
import cats.effect.kernel.GenTemporal.handleDuration
import cats.effect.std.{Console, Env, UUIDGen}
import cats.effect.std.{Backpressure, Console, Env, Supervisor, UUIDGen}
import cats.effect.tracing.{Tracing, TracingEvent}
import cats.syntax.all._

Expand Down Expand Up @@ -497,6 +497,15 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
*/
def map[B](f: A => B): IO[B] = IO.Map(this, f, Tracing.calculateTracingEvent(f))

/**
* Applies rate limiting to this `IO` based on provided backpressure semantics.
*
* @return
* an Option which denotes if this `IO` was run or not according to backpressure semantics
*/
def metered(backpressure: Backpressure[IO]): IO[Option[A]] =
backpressure.metered(this)

def onCancel(fin: IO[Unit]): IO[A] =
IO.OnCancel(this, fin)

Expand Down Expand Up @@ -610,6 +619,15 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
else
flatMap(_ => replicateA_(n - 1))

/**
* Starts this `IO` on the supervisor.
*
* @return
* a [[cats.effect.kernel.Fiber]] that represents a handle to the started fiber.
*/
def supervise(supervisor: Supervisor[IO]): IO[Fiber[IO, Throwable, A @uncheckedVariance]] =
supervisor.supervise(this)

/**
* Logs the value of this `IO` _(even if it is an error or if it was cancelled)_ to the
* standard output, using the implicit `cats.Show` instance.
Expand Down Expand Up @@ -735,6 +753,11 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
def timed: IO[(FiniteDuration, A)] =
Clock[IO].timed(this)

/**
* Lifts this `IO` into a resource. The resource has a no-op release.
*/
def toResource: Resource[IO, A] = Resource.eval(this)

def product[B](that: IO[B]): IO[(A, B)] =
flatMap(a => that.map(b => (a, b)))

Expand Down

0 comments on commit 52b5a3b

Please sign in to comment.