From 34d21807b1b730c73bfe4a1dbeb88ad2c9cce1cb Mon Sep 17 00:00:00 2001 From: Luca Tassinari Date: Wed, 10 Jan 2024 12:44:12 +0100 Subject: [PATCH] fix: protect concurrent access with synchronized --- .../scala/io/github/tassiLuca/gears/posts/PostsService.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/io/github/tassiLuca/gears/posts/PostsService.scala b/src/main/scala/io/github/tassiLuca/gears/posts/PostsService.scala index 051894fe..18751fcc 100644 --- a/src/main/scala/io/github/tassiLuca/gears/posts/PostsService.scala +++ b/src/main/scala/io/github/tassiLuca/gears/posts/PostsService.scala @@ -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] =