Packages

  • package root
    Definition Classes
    root
  • package zio
    Definition Classes
    root
  • package internal
    Definition Classes
    zio
  • package metrics
    Definition Classes
    zio
  • package stm
    Definition Classes
    zio
  • STM
  • TArray
  • TMap
  • TPriorityQueue
  • TPromise
  • TRandom
  • TReentrantLock
  • TRef
  • TSemaphore
  • TSet
  • ZSTM
  • ZTHub
  • ZTQueue
  • ZTRef
  • package stream
    Definition Classes
    zio
  • package test

    _ZIO Test_ is a featherweight testing library for effectful programs.

    _ZIO Test_ is a featherweight testing library for effectful programs.

    The library imagines every spec as an ordinary immutable value, providing tremendous potential for composition. Thanks to tight integration with ZIO, specs can use resources (including those requiring disposal), have well- defined linear and parallel semantics, and can benefit from a host of ZIO combinators.

    import zio.test._
    import zio.test.environment.Live
    import zio.Clock.nanoTime
    import Assertion.isGreaterThan
    
    object MyTest extends DefaultRunnableSpec {
      def spec = suite("clock")(
        test("time is non-zero") {
          for {
            time <- Live.live(nanoTime)
          } yield assertTrue(time >= 0)
        }
      )
    }
    Definition Classes
    zio
p

zio

stm

package stm

Linear Supertypes
EitherCompat, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. stm
  2. EitherCompat
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. type ETRef[+E, A] = ZTRef[E, E, A, A]
  2. type RSTM[-R, +A] = ZSTM[R, Throwable, A]
  3. type STM[+E, +A] = ZSTM[Any, E, A]
  4. final class TArray[A] extends AnyVal

    Wraps array of TRef and adds methods for convenience.

  5. type TDequeue[+A] = ZTQueue[Nothing, Any, Any, Nothing, Nothing, A]
  6. type TEnqueue[-A] = ZTQueue[Any, Nothing, Nothing, Any, A, Any]
  7. type THub[A] = ZTHub[Any, Any, Nothing, Nothing, A, A]
  8. final class TMap[K, V] extends AnyRef

    Transactional map implemented on top of TRef and TArray.

    Transactional map implemented on top of TRef and TArray. Resolves conflicts via chaining.

  9. final class TPriorityQueue[A] extends AnyVal

    A TPriorityQueue contains values of type A that an Ordering is defined on.

    A TPriorityQueue contains values of type A that an Ordering is defined on. Unlike a TQueue, take returns the highest priority value (the value that is first in the specified ordering) as opposed to the first value offered to the queue. The ordering that elements with the same priority will be taken from the queue is not guaranteed.

  10. final class TPromise[E, A] extends AnyVal
  11. type TQueue[A] = ZTQueue[Any, Any, Nothing, Nothing, A, A]
  12. trait TRandom extends AnyRef
  13. final class TReentrantLock extends AnyRef

    A TReentrantLock is a reentrant read/write lock.

    A TReentrantLock is a reentrant read/write lock. Multiple readers may all concurrently acquire read locks. Only one writer is allowed to acquire a write lock at any given time. Read locks may be upgraded into write locks. A fiber that has a write lock may acquire other write locks or read locks.

    The two primary methods of this structure are readLock, which acquires a read lock in a managed context, and writeLock, which acquires a write lock in a managed context.

    Although located in the STM package, there is no need for locks within STM transactions. However, this lock can be quite useful in effectful code, to provide consistent read/write access to mutable state; and being in STM allows this structure to be composed into more complicated concurrent structures that are consumed from effectful code.

  14. type TRef[A] = ZTRef[Nothing, Nothing, A, A]
  15. final class TSemaphore extends Serializable

    A TSemaphore is a semaphore that can be composed transactionally.

    A TSemaphore is a semaphore that can be composed transactionally. Because of the extremely high performance of ZIO's implementation of software transactional memory TSemaphore can support both controlling access to some resource on a standalone basis as well as composing with other STM data structures to solve more advanced concurrency problems.

    For basic use cases, the most idiomatic way to work with a semaphore is to use the withPermit operator, which acquires a permit before executing some ZIO effect and release the permit immediately afterward. The permit is guaranteed to be released immediately after the effect completes execution, whether by success, failure, or interruption. Attempting to acquire a permit when a sufficient number of permits are not available will semantically block until permits become available without blocking any underlying operating system threads. If you want to acquire more than one permit at a time you can use withPermits, which allows specifying a number of permits to acquire. You can also use withPermitManaged or withPermitsManaged to acquire and release permits within the context of a managed effect for composing with other resources.

    For more advanced concurrency problems you can use the acquire and release operators directly, or their variants acquireN and releaseN, all of which return STM transactions. Thus, they can be composed to form larger STM transactions, for example acquiring permits from two different semaphores transactionally and later releasing them transactionally to safely synchronize on access to two different mutable variables.

  16. final class TSet[A] extends AnyVal

    Transactional set implemented on top of TMap.

  17. type TaskSTM[+A] = ZSTM[Any, Throwable, A]
  18. type URSTM[-R, +A] = ZSTM[R, Nothing, A]
  19. type USTM[+A] = ZSTM[Any, Nothing, A]
  20. sealed trait ZSTM[-R, +E, +A] extends Serializable

    STM[E, A] represents an effect that can be performed transactionally, resulting in a failure E or a value A.

    STM[E, A] represents an effect that can be performed transactionally, resulting in a failure E or a value A.

    def transfer(receiver: TRef[Int],
                 sender: TRef[Int], much: Int): UIO[Int] =
      STM.atomically {
        for {
          balance <- sender.get
          _       <- STM.check(balance >= much)
          _       <- receiver.update(_ + much)
          _       <- sender.update(_ - much)
          newAmnt <- receiver.get
        } yield newAmnt
      }
    
      val action: UIO[Int] =
        for {
          t <- STM.atomically(TRef.make(0).zip(TRef.make(20000)))
          (receiver, sender) = t
          balance <- transfer(receiver, sender, 1000)
        } yield balance

    Software Transactional Memory is a technique which allows composition of arbitrary atomic operations. It is the software analog of transactions in database systems.

    The API is lifted directly from the Haskell package Control.Concurrent.STM although the implementation does not resemble the Haskell one at all. http://hackage.haskell.org/package/stm-2.5.0.0/docs/Control-Concurrent-STM.html

    STM in Haskell was introduced in: Composable memory transactions, by Tim Harris, Simon Marlow, Simon Peyton Jones, and Maurice Herlihy, in ACM Conference on Principles and Practice of Parallel Programming 2005. https://www.microsoft.com/en-us/research/publication/composable-memory-transactions/

    See also: Lock Free Data Structures using STMs in Haskell, by Anthony Discolo, Tim Harris, Simon Marlow, Simon Peyton Jones, Satnam Singh) FLOPS 2006: Eighth International Symposium on Functional and Logic Programming, Fuji Susono, JAPAN, April 2006 https://www.microsoft.com/en-us/research/publication/lock-free-data-structures-using-stms-in-haskell/

  21. type ZTDequeue[-R, +E, +A] = ZTQueue[Nothing, R, Any, E, Nothing, A]

    A transactional queue that can only be dequeued.

  22. type ZTEnqueue[-R, +E, -A] = ZTQueue[R, Nothing, E, Any, A, Any]

    A transactional queue that can only be enqueued.

  23. sealed abstract class ZTHub[-RA, -RB, +EA, +EB, -A, +B] extends Serializable

    A ZTHub[RA, RB, EA, EB, A, B] is a transactional message hub.

    A ZTHub[RA, RB, EA, EB, A, B] is a transactional message hub. Publishers can publish messages of type A to the hub and subscribers can subscribe to take messages of type B from the hub. Publishing messages can require an environment of type RA and fail with an error of type EA. Taking messages can require an environment of type RB and fail with an error of type EB.

  24. trait ZTQueue[-RA, -RB, +EA, +EB, -A, +B] extends Serializable

    A ZTQueue[RA, RB, EA, EB, A, B] is a transactional queue.

    A ZTQueue[RA, RB, EA, EB, A, B] is a transactional queue. Offerors can offer values of type A to the queue and takers can take values of type B from the queue. Offering values can require an environment of type RA and fail with an error of type EA. Taking values can require an environment of type RB and fail with an error of type EB.

  25. sealed abstract class ZTRef[+EA, +EB, -A, +B] extends Serializable

    A ZTRef[EA, EB, A, B] is a polymorphic, purely functional description of a mutable reference that can be modified as part of a transactional effect.

    A ZTRef[EA, EB, A, B] is a polymorphic, purely functional description of a mutable reference that can be modified as part of a transactional effect. The fundamental operations of a ZTRef are set and get. set takes a value of type A and transactionally sets the reference to a new value, potentially failing with an error of type EA. get gets the current value of the reference and returns a value of type B, potentially failing with an error of type EB.

    When the error and value types of the ZTRef are unified, that is, it is a ZTRef[E, E, A, A], the ZTRef also supports atomic modify and update operations. All operations are guaranteed to be executed transactionally.

    NOTE: While ZTRef provides the transactional equivalent of a mutable reference, the value inside the ZTRef should be immutable. For performance reasons ZTRef is implemented in terms of compare and swap operations rather than synchronization. These operations are not safe for mutable values that do not support concurrent access.

Value Members

  1. val THub: ZTHub.type
  2. val TQueue: ZTQueue.type
  3. object STM
  4. object TArray
  5. object TMap
  6. object TPriorityQueue
  7. object TPromise
  8. object TRandom extends Serializable
  9. object TReentrantLock
  10. object TRef
  11. object TSemaphore extends Serializable
  12. object TSet
  13. object ZSTM extends Serializable
  14. object ZTHub extends Serializable
  15. object ZTQueue extends Serializable
  16. object ZTRef extends Serializable

Inherited from EitherCompat

Inherited from AnyRef

Inherited from Any

Ungrouped