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
|
@ImplicitReflectionSerializer
|
||||||
private fun generateId(): PostId = UUID.randomUUID().toString()
|
private fun generateId(): PostId = UUID.randomUUID().toString()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread-unsafe sample realization of [PostsAPI]
|
||||||
|
*/
|
||||||
@ImplicitReflectionSerializer
|
@ImplicitReflectionSerializer
|
||||||
class InMemoryPostsAPI(
|
class InMemoryPostsAPI(
|
||||||
initialPosts: List<RegisteredPost> = emptyList()
|
initialPosts: List<RegisteredPost> = emptyList()
|
||||||
@ -34,7 +37,6 @@ class InMemoryPostsAPI(
|
|||||||
override val postUpdatedFlow: Flow<RegisteredPost> = postUpdatedBroadcastChannel.asFlow()
|
override val postUpdatedFlow: Flow<RegisteredPost> = postUpdatedBroadcastChannel.asFlow()
|
||||||
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override suspend fun createPost(post: Post): RegisteredPost? {
|
override suspend fun createPost(post: Post): RegisteredPost? {
|
||||||
return SimpleRegisteredPost(
|
return SimpleRegisteredPost(
|
||||||
generateId(),
|
generateId(),
|
||||||
@ -45,14 +47,12 @@ class InMemoryPostsAPI(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override suspend fun deletePost(id: PostId): Boolean {
|
override suspend fun deletePost(id: PostId): Boolean {
|
||||||
return posts.remove(id) ?.also {
|
return posts.remove(id) ?.also {
|
||||||
postDeletedBroadcastChannel.send(it)
|
postDeletedBroadcastChannel.send(it)
|
||||||
} != null
|
} != null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override suspend fun updatePostContent(postId: PostId, post: Post): Boolean {
|
override suspend fun updatePostContent(postId: PostId, post: Post): Boolean {
|
||||||
return getPostById(postId) ?.also { dbPost ->
|
return getPostById(postId) ?.also { dbPost ->
|
||||||
val newPost = SimpleRegisteredPost(
|
val newPost = SimpleRegisteredPost(
|
||||||
|
Loading…
Reference in New Issue
Block a user