Skip to content

pico-works/pico-atomic

Repository files navigation

pico-atomic

CircleCI Codacy Badge Codacy Badge Gitter chat

Support library for atomic operations.

Getting started

Add this to your SBT project:

resolvers += "dl-john-ky-releases" at "http://dl.john-ky.io/maven/releases"

libraryDependencies += "org.pico" %%  "pico-atomic" % "0.2.2"

Atomic updates

A value can be updated atomically with a transformation function using the update method:

  import org.pico.atomic.syntax.std.atomicInteger._
  import java.util.concurrent.atomic.AtomicInteger
  val ref = new AtomicInteger(1)
  ref.update(_ + 1) must_=== (1, 2)
  ref.value must_=== 2

  import org.pico.atomic.syntax.std.atomicReference._
  import java.util.concurrent.atomic.AtomicReference
  val ref = new AtomicReference[Int](1)
  ref.update(_ + 1) must_=== (1, 2)
  ref.value must_=== 2

The update function will retry applying the transformation function until a successful atomic update occurs.

Swap method

The swap method is equivalent to getAndSet, just with a shorter name.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •