https://github.com/evolution-gaming/serially
https://github.com/evolution-gaming/serially
akka concurrency scala
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/evolution-gaming/serially
- Owner: evolution-gaming
- License: mit
- Created: 2018-05-04T16:59:12.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-29T14:17:24.000Z (almost 2 years ago)
- Last Synced: 2025-04-02T16:14:21.377Z (about 1 year ago)
- Topics: akka, concurrency, scala
- Language: Scala
- Size: 80.1 KB
- Stars: 1
- Watchers: 10
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serially
[](https://github.com/evolution-gaming/serially/actions?query=workflow%3ACI)
[](https://coveralls.io/github/evolution-gaming/serially?branch=master)
[](https://www.codacy.com/app/evolution-gaming/serially?utm_source=github.com&utm_medium=referral&utm_content=evolution-gaming/serially&utm_campaign=Badge_Grade)
[](https://evolution.jfrog.io/artifactory/api/search/latestVersion?g=com.evolutiongaming&a=serially_2.13&repos=public)
[](https://opensource.org/licenses/MIT)
This library contains `Serially.scala` which allows to run tasks serially
The behavior is somehow similar to what actors propose, however it provides typesafety.
Also it is easy to write tests using `Serially.now` to avoid unnecessary concurrency.
## `Serially` example
This example explains how we can ensure that there are no concurrent updates to `var state`
```scala
val system = ActorSystem() // yes, we have dependency on akka
val serially = Serially()
var state: Int = 0
// this runs sequentially, like message handling in actors
serially {
state = state + 1
}
// you also can expose computation result as Future[T]
val stateBefore: Future[Int] = serially {
val stateBefore = state
state = state + 1
stateBefore
}
```
## `StateVar` example
Basically the same as on previous example with less code
```scala
val system = ActorSystem()
val serially = Serially()
val state = StateVar(0, serially)
val result: Future[String] = state { before =>
val after = before + 1
(after, "ok")
}
```
## Setup
```scala
addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")
libraryDependencies += "com.evolutiongaming" %% "serially" % "1.0.6"
```