~thatonelutenist/actm

0bc2cf691f0994c7ec8e41cb64034917e3c4de6f — Nathan McCarty 1 year, 9 months ago fd415d2
refactor!: Remove priority system

BREAKING CHANGE: Priority methods have been removed from the Event and
EventProducer traits.
4 files changed, 3 insertions(+), 57 deletions(-)

M src/traits.rs
M src/types.rs
M src/util/token_manager.rs
M src/util/wrapped_event.rs
M src/traits.rs => src/traits.rs +0 -28
@@ 28,10 28,6 @@ pub trait Event: Eq + Debug + Ord + Hash + Send + Sync + 'static {
    ///
    /// This method is allowed to block, and should always be run on the blocking thread pool.
    fn flags(&self) -> Self::Flags;
    /// Indicates that this `Event` should be prioritized
    fn priority(&self) -> bool {
        false
    }
    /// This method returns the associated [`CompletionToken`], if the event is associated with one.
    /// In order to comply with the [`CompletionToken`] contract, this method **must** move the
    /// existing [`CompletionToken`] out of the `Event`, and **must not** copy it.


@@ 128,17 124,6 @@ pub trait EventProducer<E: Event>: Send + Sync + 'static {
    async fn register_consumer<C>(&self, consumer: C) -> Result<(), Self::Error>
    where
        C: EventConsumer<E> + Send + Sync + 'static;
    /// Registers a priority handler that gets called early on high priority events
    ///
    /// # Errors
    ///
    /// Can return an implementation defined error if registering the consumer fails
    async fn register_priority_consumer<C>(&self, consumer: C) -> Result<(), Self::Error>
    where
        C: EventConsumer<E> + Send + Sync + 'static,
    {
        self.register_consumer(consumer).await
    }
    /// Registers a callback to be called on the completion of the computation associated with a
    /// [`CompletionToken`]
    async fn register_callback<F>(


@@ 159,19 144,6 @@ pub trait EventProducer<E: Event>: Send + Sync + 'static {
    fn register_consumer_sync<C>(&self, consumer: C) -> Result<(), Self::Error>
    where
        C: EventConsumer<E> + Send + Sync + 'static;
    /// Registers a priority handler that gets called early on high priority events
    ///
    /// Blocks if required
    ///
    /// # Errors
    ///
    /// Can return an implementation defined error if registering the consumer fails
    fn register_priority_consumer_sync<C>(&self, consumer: C) -> Result<(), Self::Error>
    where
        C: EventConsumer<E> + Send + Sync + 'static,
    {
        self.register_consumer_sync(consumer)
    }
    /// Registers a callback to be called on the completion of the computation associated with a
    /// [`CompletionToken`]
    ///

M src/types.rs => src/types.rs +0 -7
@@ 72,13 72,6 @@ impl<I: Event, O: Event> Event for DirectionalEvent<I, O> {
        }
    }

    fn priority(&self) -> bool {
        match self {
            DirectionalEvent::Inbound(e) => e.priority(),
            DirectionalEvent::Outbound(e) => e.priority(),
        }
    }

    fn token(&mut self) -> Option<CompletionToken> {
        match self {
            DirectionalEvent::Inbound(e) => e.token(),

M src/util/token_manager.rs => src/util/token_manager.rs +0 -4
@@ 292,10 292,6 @@ mod tests {
            }
        }

        fn priority(&self) -> bool {
            false
        }

        fn token(&mut self) -> Option<CompletionToken> {
            self.token.take()
        }

M src/util/wrapped_event.rs => src/util/wrapped_event.rs +3 -18
@@ 7,7 7,7 @@ use crate::{traits::Event, types::CompletionToken};
/// controlled state variables to implement the [`Event`] api, with no business logic aside from the
/// provided setters.
#[derive(PartialEq, Eq, Debug, PartialOrd, Ord, Hash, Default)]
pub struct WrappedEvent<T>(T, Option<CompletionToken>, bool);
pub struct WrappedEvent<T>(T, Option<CompletionToken>);

impl<T> WrappedEvent<T> {
    /// Converts back to the contained type


@@ 18,16 18,11 @@ impl<T> WrappedEvent<T> {
    pub fn set_completion_token(&mut self, token: CompletionToken) {
        self.1 = Some(token);
    }

    /// Sets the priority flag
    pub fn set_priority(&mut self, priority: bool) {
        self.2 = priority;
    }
}

impl<T> From<T> for WrappedEvent<T> {
    fn from(item: T) -> Self {
        Self(item, None, false)
        Self(item, None)
    }
}



@@ 39,10 34,6 @@ where

    fn flags(&self) -> Self::Flags {}

    fn priority(&self) -> bool {
        self.2
    }

    fn token(&mut self) -> Option<CompletionToken> {
        self.1.take()
    }


@@ 54,7 45,7 @@ where
    }

    fn stateless_clone(&self) -> Self {
        Self(self.0.clone(), None, self.2)
        Self(self.0.clone(), None)
    }
}



@@ 71,9 62,6 @@ macro_rules! wrapped_event {
            pub fn set_completion_token(&mut self, token: CompletionToken) {
                self.0.set_completion_token(token);
            }
            pub fn set_priority(&mut self, priority: bool) {
                self.0.set_priority(priority);
            }
        }
        impl From<$event_type> for $wrapper_name {
            fn from(item: $event_type) -> Self {


@@ 83,9 71,6 @@ macro_rules! wrapped_event {
        impl Event for $wrapper_name {
            type Flags = ();
            fn flags(&self) -> Self::Flags {}
            fn priority(&self) -> bool {
                self.0.priority()
            }
            fn token(&mut self) -> Option<CompletionToken> {
                self.0.token()
            }