Skip to content

Commit

Permalink
Some extra effects doc (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntc authored Nov 7, 2023
1 parent 1fd82a7 commit 05042a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 11 additions & 1 deletion akka-persistence-rs/src/effect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
//! Effects that are lazily performed as a result of performing a command
//! of an entity. Effects can be chained with other effects.
//! of an entity. Effects can be chained with other effects and are guaranteed
//! to be applied (run) before the next command for an entity id is processed.
//!
//! Convience methods are providing for commonly chained operations, and take
//! the form of `and_then` as the prefix. By Rust convention, `and_then`
//! provides the result of the previous operation and expects a result provided
//! given some closure.
//!
//! In the case where there is no convenience method, a generalized `and`
//! operation can be used to chain any effect found here, or a customized
//! effect.

use async_trait::async_trait;
use chrono::Utc;
Expand Down
2 changes: 2 additions & 0 deletions akka-persistence-rs/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub trait EventSourcedBehavior {
/// State can also be associated with the behavior so that other effects can be
/// performed. For example, a behavior might be created with a channel sender
/// so that data can be sent as an effect of performing a command.
/// Effects can be chained and are guaranteed to be applied in their entirety
/// before the next command for their entity id is processed.
fn for_command(
context: &Context,
state: &Self::State,
Expand Down
12 changes: 5 additions & 7 deletions akka-persistence-rs/src/entity_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ where

#[cfg(test)]
mod tests {
use std::{io, pin::Pin, sync::Arc};
use std::{future, io, pin::Pin, sync::Arc};

use super::*;
use crate::{
Expand Down Expand Up @@ -378,13 +378,11 @@ mod tests {
.and_then(|behavior: &Self, new_state, prev_result| {
let updated = behavior.updated.clone();
let temp = new_state.map_or(0, |s| s.temp);
async move {
if prev_result.is_ok() {
updated.notify_one();
println!("Updated with {}!", temp);
}
prev_result
if prev_result.is_ok() {
updated.notify_one();
println!("Updated with {}!", temp);
}
future::ready(prev_result)
})
.boxed()
}
Expand Down

0 comments on commit 05042a9

Please sign in to comment.