Skip to content

Commit 62da9bb

Browse files
committed
add user manual docs for PState.modifyF
1 parent 4f61fe1 commit 62da9bb

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

longevity/src/jekyll/manual/repo/persistent-state.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ We have just provided a guarantee - at virtually no cost - that
5656
persistence concerns can not leak into the `UserService`
5757
implementation.
5858

59+
What if our service method was an effectful method? Perhaps it has to hit another blocking service
60+
somewhere to do its work, such as when hitting another
61+
[microservice](https://www.martinfowler.com/articles/microservices.html) in the application? In
62+
this case, we would probably be wrapping it in a future-like construct in a reactive setting, or in
63+
an IO monad construct in more of a functional setting. Let's use `scala.concurrent.Future` as an
64+
example:
65+
66+
```scala
67+
trait UserService {
68+
def updateScoreCard(user: User, event: PointScoredEvent): Future[User]
69+
}
70+
```
71+
72+
We can change our above example to call `modifyF` instead of `modify`, like so:
73+
74+
```scala
75+
val updatedState: Future[PState[User]] = userState.modifyF { user =>
76+
userService.updateScoreCard(user, event)
77+
}
78+
```
79+
80+
The persistent state does not inherit the effect from the repository. This means you will have to
81+
make an effect implicitly available when calling `modifyF`, in the same way as when you [created
82+
your longevity context](../context/effect.html). (The persistent state could easily inherit the
83+
effect from the repository, and perhaps it should. The advantage of inheriting the effect is that
84+
the user would not need to supply the effect again when calling `modifyF`. The disadvantage is that
85+
the type gets more cumbersome. For instance, `PState[User]` would become `PState[Future, User]`.)
86+
5987
{% assign prevTitle = "schema creation" %}
6088
{% assign prevLink = "schema-creation.html" %}
6189
{% assign upTitle = "the repository" %}

longevity/src/jekyll/resources.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ layout: page
1414
Google Groups. Please drop a line! We really want to hear from you!
1515

1616
- [License](license.html) - Apache 2
17-
- [Longevity By Design](http://www.longevitybydesign.net/) - A consulting firm
18-
specializing in helping you get started using longevity
1917
- [How You Can Contribute](contributing.html) - We are always squeezed
2018
for hours to work on this code, and there are loads of great
2119
features to be implemented. Please consider contributing.

0 commit comments

Comments
 (0)