Skip to content

Commit

Permalink
fix: protect concurrent access with synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
tassiluca committed Jan 10, 2024
1 parent 78e5b24 commit 34d2180
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait PostsRepositoryComponent:
require(posts.count(_.title == post.title) == 0, "A post with same title has already been saved")
println(s"[PostsRepository - ${Thread.currentThread()}] Saving post $post...")
sleep(3_000)
posts = posts + post
synchronized { posts = posts + post }
true

override def load(postTitle: Title)(using Async): Option[Post] =
Expand Down

0 comments on commit 34d2180

Please sign in to comment.