Packages

final class SyncIO[+A] extends AnyRef

A pure abstraction representing the intention to perform a side effect, where the result of that side effect is obtained synchronously.

SyncIO is similar to IO, but does not support asynchronous computations. Consequently, a SyncIO can be run synchronously to obtain a result via unsafeRunSync. This is unlike IO#unsafeRunSync, which cannot be safely called in general -- doing so on the JVM blocks the calling thread while the async part of the computation is run and doing so on Scala.js throws an exception upon encountering an async boundary.

Source
SyncIO.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SyncIO
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def attempt: SyncIO[Either[Throwable, A]]

    Materializes any sequenced exceptions into value space, where they may be handled.

    Materializes any sequenced exceptions into value space, where they may be handled.

    This is analogous to the catch clause in try/catch, being the inverse of SyncIO.raiseError. Thus:

    SyncIO.raiseError(ex).attempt.unsafeRunSync === Left(ex)
    See also

    SyncIO.raiseError

  6. def bracket[B](use: (A) => SyncIO[B])(release: (A) => SyncIO[Unit]): SyncIO[B]

    Returns a SyncIO action that treats the source task as the acquisition of a resource, which is then exploited by the use function and then released.

    Returns a SyncIO action that treats the source task as the acquisition of a resource, which is then exploited by the use function and then released.

    The bracket operation is the equivalent of the try {} catch {} finally {} statements from mainstream languages.

    The bracket operation installs the necessary exception handler to release the resource in the event of an exception being raised during the computation.

    If an exception is raised, then bracket will re-raise the exception after performing the release.

    NOTE on error handling: one big difference versus try/finally statements is that, in case both the release function and the use function throws, the error raised by use gets signaled.

    For example:

    SyncIO("resource").bracket { _ =>
      // use
      SyncIO.raiseError(new RuntimeException("Foo"))
    } { _ =>
      // release
      SyncIO.raiseError(new RuntimeException("Bar"))
    }

    In this case the error signaled downstream is "Foo", while the "Bar" error gets reported. This is consistent with the behavior of Haskell's bracket operation and NOT with try {} finally {} from Scala, Java or JavaScript.

    use

    is a function that evaluates the resource yielded by the source, yielding a result that will get generated by the task returned by this bracket function

    release

    is a function that gets called after use terminates, either normally or in error, or if it gets canceled, receiving as input the resource that needs to be released

    See also

    bracketCase

  7. def bracketCase[B](use: (A) => SyncIO[B])(release: (A, ExitCase[Throwable]) => SyncIO[Unit]): SyncIO[B]

    Returns a new SyncIO task that treats the source task as the acquisition of a resource, which is then exploited by the use function and then released, with the possibility of distinguishing between normal termination and failure, such that an appropriate release of resources can be executed.

    Returns a new SyncIO task that treats the source task as the acquisition of a resource, which is then exploited by the use function and then released, with the possibility of distinguishing between normal termination and failure, such that an appropriate release of resources can be executed.

    The bracketCase operation is the equivalent of try {} catch {} finally {} statements from mainstream languages when used for the acquisition and release of resources.

    The bracketCase operation installs the necessary exception handler to release the resource in the event of an exception being raised during the computation.

    In comparison with the simpler bracket version, this one allows the caller to differentiate between normal termination and termination in error. Note SyncIO does not support cancelation so that exit case should be ignored.

    use

    is a function that evaluates the resource yielded by the source, yielding a result that will get generated by this function on evaluation

    release

    is a function that gets called after use terminates, either normally or in error, receiving as input the resource that needs that needs release, along with the result of use (error or successful result)

    See also

    bracket

  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  12. def flatMap[B](f: (A) => SyncIO[B]): SyncIO[B]

    Monadic bind on SyncIO, used for sequentially composing two SyncIO actions, where the value produced by the first SyncIO is passed as input to a function producing the second SyncIO action.

    Monadic bind on SyncIO, used for sequentially composing two SyncIO actions, where the value produced by the first SyncIO is passed as input to a function producing the second SyncIO action.

    Due to this operation's signature, flatMap forces a data dependency between two SyncIO actions, thus ensuring sequencing (e.g. one action to be executed before another one).

    Any exceptions thrown within the function will be caught and sequenced in to the result SyncIO[B].

  13. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. def guarantee(finalizer: SyncIO[Unit]): SyncIO[A]

    Executes the given finalizer when the source is finished, either in success or in error.

    Executes the given finalizer when the source is finished, either in success or in error.

    This variant of guaranteeCase evaluates the given finalizer regardless of how the source gets terminated:

    • normal completion
    • completion in error

    This equivalence always holds:

    io.guarantee(f) <-> IO.unit.bracket(_ => io)(_ => f)

    As best practice, it's not a good idea to release resources via guaranteeCase in polymorphic code. Prefer bracket for the acquisition and release of resources.

    See also

    guaranteeCase for the version that can discriminate between termination conditions

    bracket for the more general operation

  15. def guaranteeCase(finalizer: (ExitCase[Throwable]) => SyncIO[Unit]): SyncIO[A]

    Executes the given finalizer when the source is finished, either in success or in error, allowing for differentiating between exit conditions.

    Executes the given finalizer when the source is finished, either in success or in error, allowing for differentiating between exit conditions.

    This variant of guarantee injects an ExitCase in the provided function, allowing one to make a difference between:

    • normal completion
    • completion in error

    This equivalence always holds:

    io.guaranteeCase(f) <-> IO.unit.bracketCase(_ => io)((_, e) => f(e))

    As best practice, it's not a good idea to release resources via guaranteeCase in polymorphic code. Prefer bracketCase for the acquisition and release of resources.

    See also

    guarantee for the simpler version

    bracketCase for the more general operation

  16. def handleErrorWith[AA >: A](f: (Throwable) => SyncIO[AA]): SyncIO[AA]

    Handle any error, potentially recovering from it, by mapping it to another SyncIO value.

    Handle any error, potentially recovering from it, by mapping it to another SyncIO value.

    Implements ApplicativeError.handleErrorWith.

  17. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. def map[B](f: (A) => B): SyncIO[B]

    Functor map on SyncIO.

    Functor map on SyncIO. Given a mapping function, it transforms the value produced by the source, while keeping the SyncIO context.

    Any exceptions thrown within the function will be caught and sequenced in to the result SyncIO[B].

  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. def redeem[B](recover: (Throwable) => B, map: (A) => B): SyncIO[B]

    Returns a new value that transforms the result of the source, given the recover or map functions, which get executed depending on whether the result ends in error or if it is successful.

    Returns a new value that transforms the result of the source, given the recover or map functions, which get executed depending on whether the result ends in error or if it is successful.

    This is an optimization on usage of attempt and map, this equivalence being true:

    io.redeem(recover, map) <-> io.attempt.map(_.fold(recover, map))

    Usage of redeem subsumes handleError because:

    io.redeem(fe, id) <-> io.handleError(fe)
    recover

    is a function used for error recover in case the source ends in error

    map

    is a function used for mapping the result of the source in case it ends in success

  24. def redeemWith[B](recover: (Throwable) => SyncIO[B], bind: (A) => SyncIO[B]): SyncIO[B]

    Returns a new value that transforms the result of the source, given the recover or bind functions, which get executed depending on whether the result ends in error or if it is successful.

    Returns a new value that transforms the result of the source, given the recover or bind functions, which get executed depending on whether the result ends in error or if it is successful.

    This is an optimization on usage of attempt and flatMap, this equivalence being available:

    io.redeemWith(recover, bind) <-> io.attempt.flatMap(_.fold(recover, bind))

    Usage of redeemWith subsumes handleErrorWith because:

    io.redeemWith(fe, F.pure) <-> io.handleErrorWith(fe)

    Usage of redeemWith also subsumes flatMap because:

    io.redeemWith(F.raiseError, fs) <-> io.flatMap(fs)
    recover

    is the function that gets called to recover the source in case of error

    bind

    is the function that gets to transform the source in case of success

  25. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  26. def to[F[_]](implicit F: LiftIO[F]): F[A]

    Converts the source IO into any F type that implements the LiftIO type class.

  27. def toIO: IO[A]
  28. def toString(): String
    Definition Classes
    SyncIO → AnyRef → Any
  29. def unsafeRunSync(): A

    Produces the result by running the encapsulated effects as impure side effects.

    Produces the result by running the encapsulated effects as impure side effects.

    Any exceptions raised within the effect will be re-thrown during evaluation.

    As the name says, this is an UNSAFE function as it is impure and performs side effects and throws exceptions. You should ideally only call this function *once*, at the very end of your program.

  30. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped