Skip to content

chore: simplify actor's context#1955

Open
SantiagoPittella wants to merge 4 commits intonextfrom
santiagopittella-simplify-actor-context
Open

chore: simplify actor's context#1955
SantiagoPittella wants to merge 4 commits intonextfrom
santiagopittella-simplify-actor-context

Conversation

@SantiagoPittella
Copy link
Copy Markdown
Collaborator

closes #1889

@SantiagoPittella SantiagoPittella added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Apr 17, 2026
Copy link
Copy Markdown
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

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

Looks good, barring the notify change

Comment thread crates/ntx-builder/src/coordinator.rs Outdated
/// Used after an actor has shut down to detect the race where a notification arrived just as
/// the actor timed out; if so, the coordinator should respawn the actor.
fn has_pending_notification(&self) -> bool {
self.notify.max_capacity() > self.notify.capacity()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume you changed from Notify because you couldn't determine if it had a pending notification?

I think you should be able to something like the following

/// Returns `true` if there is an unread notification by the actor.
fn has_pending_notification(&self) -> bool {
    use futures::FutureExt;

    let mut fut = self.notify.notified();
    if fut.now_or_never().is_ready() {
        // Replace the notification to keep the state the same as before.
        // Only required because fn signature doesn't consume.
        self.notified.notify_one();
        true
    } else {
        false
    }
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, exactly. The now_or_never trick didn't occur to me, so I went with mpsc::channel(1).
With this approach I can go back to Arc<Notify> with a little twist.

Copy link
Copy Markdown
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify actor context

2 participants