Wrap Post in PostEvent with Arc

See https://github.com/riker-rs/riker/issues/153
This commit is contained in:
Kitaiti Makoto 2021-01-12 09:27:55 +09:00
parent 6c1dd6608d
commit 6dd730030d
1 changed files with 8 additions and 7 deletions

View File

@ -21,6 +21,7 @@ use plume_common::{
}; };
use riker::actors::{Publish, Tell}; use riker::actors::{Publish, Tell};
use std::collections::HashSet; use std::collections::HashSet;
use std::sync::Arc;
pub type LicensedArticle = CustomObject<Licensed, Article>; pub type LicensedArticle = CustomObject<Licensed, Article>;
@ -556,7 +557,7 @@ impl Post {
fn publish_published(&self) { fn publish_published(&self) {
POST_CHAN.tell( POST_CHAN.tell(
Publish { Publish {
msg: PostPublished(self.clone()), msg: PostPublished(Arc::new(self.clone())),
topic: "post.published".into(), topic: "post.published".into(),
}, },
None, None,
@ -566,7 +567,7 @@ impl Post {
fn publish_updated(&self) { fn publish_updated(&self) {
POST_CHAN.tell( POST_CHAN.tell(
Publish { Publish {
msg: PostUpdated(self.clone()), msg: PostUpdated(Arc::new(self.clone())),
topic: "post.updated".into(), topic: "post.updated".into(),
}, },
None, None,
@ -576,7 +577,7 @@ impl Post {
fn publish_deleted(&self) { fn publish_deleted(&self) {
POST_CHAN.tell( POST_CHAN.tell(
Publish { Publish {
msg: PostDeleted(self.clone()), msg: PostDeleted(Arc::new(self.clone())),
topic: "post.deleted".into(), topic: "post.deleted".into(),
}, },
None, None,
@ -836,12 +837,12 @@ impl IntoId for Post {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum PostEvent { pub enum PostEvent {
PostPublished(Post), PostPublished(Arc<Post>),
PostUpdated(Post), PostUpdated(Arc<Post>),
PostDeleted(Post), PostDeleted(Arc<Post>),
} }
impl From<PostEvent> for Post { impl From<PostEvent> for Arc<Post> {
fn from(event: PostEvent) -> Self { fn from(event: PostEvent) -> Self {
use PostEvent::*; use PostEvent::*;