remove @Synchronized and add comment about thread-unsafety of InMemoryPostsAPI
This commit is contained in:
parent
53436cf057
commit
518064cc1b
@ -15,6 +15,9 @@ import java.util.*
|
||||
@ImplicitReflectionSerializer
|
||||
private fun generateId(): PostId = UUID.randomUUID().toString()
|
||||
|
||||
/**
|
||||
* Thread-unsafe sample realization of [PostsAPI]
|
||||
*/
|
||||
@ImplicitReflectionSerializer
|
||||
class InMemoryPostsAPI(
|
||||
initialPosts: List<RegisteredPost> = emptyList()
|
||||
@ -34,7 +37,6 @@ class InMemoryPostsAPI(
|
||||
override val postUpdatedFlow: Flow<RegisteredPost> = postUpdatedBroadcastChannel.asFlow()
|
||||
|
||||
|
||||
@Synchronized
|
||||
override suspend fun createPost(post: Post): RegisteredPost? {
|
||||
return SimpleRegisteredPost(
|
||||
generateId(),
|
||||
@ -45,14 +47,12 @@ class InMemoryPostsAPI(
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override suspend fun deletePost(id: PostId): Boolean {
|
||||
return posts.remove(id) ?.also {
|
||||
postDeletedBroadcastChannel.send(it)
|
||||
} != null
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override suspend fun updatePostContent(postId: PostId, post: Post): Boolean {
|
||||
return getPostById(postId) ?.also { dbPost ->
|
||||
val newPost = SimpleRegisteredPost(
|
||||
|
Loading…
Reference in New Issue
Block a user