Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More effect combinators #99

Merged
merged 2 commits into from
Nov 3, 2023
Merged

More effect combinators #99

merged 2 commits into from
Nov 3, 2023

Conversation

huntc
Copy link
Collaborator

@huntc huntc commented Nov 3, 2023

Effect combinators added for emitting events and replying; both with the same abilities as and_then to inspect behaviour and state, and act in accordance with the previous result.

Here's a contrived example that I tried out:

emit_event(TempEvent::TemperatureUpdated { temp: 10 })
    .and_then_reply(|_: &Self, new_state, prev_result| {
        let result = if prev_result.is_ok() {
            if let (Some(new_state), Ok(_)) = (new_state, prev_result) {
                Ok(Some((reply_to, new_state.temp)))
            } else {
                Ok(None)
            }
        } else {
            prev_result.map(|_| None)
        };

        async { result }
    })
    .and_then_emit_event(|_, _, _| async {
        Ok(Some(TempEvent::TemperatureUpdated { temp: 20 }))
    })
    .boxed()

The change here principally fixes a bug where we weren't recovering the last offset of the offset store correctly. However, I then found a race condition where the consumer projection wasn't waiting for the offset store to finish its recovery. Further, the offset store had no means to convey that it had fully recovery, nor any entity manager for that matter. Consequently, a new `on_initial_recovery_completed` method has been added to the entity behaviour trait.
Effect combinators added for emitting events and replying; both with the same abilities as `and_then` to inspect behaviour and state, and act in accordance with the previous result.
@huntc huntc added the enhancement New feature or request label Nov 3, 2023
@huntc huntc requested a review from patriknw November 3, 2023 06:00
@huntc huntc self-assigned this Nov 3, 2023
Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/// An effect to emit a deletion event. The latest state given any previous effect
/// having emitted an event, or else the state at the outset of the effects
/// being applied, is also available.
fn and_then_emit_deletion_event<F, R>(self, f: F) -> And<B, Self, ThenEmitEvent<B, F, R>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but we need to test what happens when deleting an entity. I assume it is possible to create a new entity with with same entity_id and then it will start from seq_nr 1 again. That will probably be confusing to the jvm side when producing events. Such events will be seen as duplicates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Interesting. We might be ok... Certainly worth testing.

Base automatically changed from recover-all to main November 3, 2023 07:04
@huntc huntc merged commit 801af51 into main Nov 3, 2023
1 check passed
@huntc huntc deleted the more-combinators branch November 3, 2023 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants