ADR-0008: Event-Driven Node Extensions¶
Status¶
Accepted
Date¶
2025-02-27
Context¶
The floxide framework is being extended with event-driven capabilities through the floxide-event
crate. This crate provides functionality for creating nodes that respond to external events and can be integrated into standard workflows. However, several issues have been identified in the current implementation:
- The
EventProcessor
struct has unused type parameters (Context
andAction
) - The
FloxideError
enum lacks methods needed by the event system (node_not_found
andtimeout
) - The
NodeOutcome::RouteToAction
variant is being used incorrectly with two arguments when it expects one - Type inference issues in several places where trait bounds cannot be properly resolved
- Missing trait implementations, specifically
Default
for theAction
type parameter - Incorrect variant names for
DefaultAction
in theEventActionExt
trait implementation
These issues need to be addressed to ensure the event-driven node extensions work correctly within the framework.
Decision¶
We will make the following changes to address the issues:
-
Fix
EventProcessor
type parameters: Update theEventProcessor
struct to either use the unused type parameters or remove them, usingPhantomData
where necessary. -
Extend
FloxideError
with required methods: Add methods to theFloxideError
type in the core crate fornode_not_found
andtimeout
functionality. -
Fix
NodeOutcome::RouteToAction
usage: Update the event crate to correctly use this variant with a single argument instead of two. -
Address type inference issues: Add proper type annotations and function signatures to improve type inference in the event-driven components.
-
Add required trait bounds: Ensure that all generic type parameters have the necessary trait bounds, including
Default
where required. -
Correct EventActionExt implementation: Fix the implementation to use the proper function syntax instead of non-existent enum variants.
-
Clean up unused imports: Remove unused imports in both the transform and event crates.
Implementation Details¶
The implementation involved the following key changes:
-
Added
node_not_found
,timeout
, andis_timeout
methods toFloxideError
in the core crate. -
Fixed
EventProcessor
by addingPhantomData
for unused type parameters and adding proper trait bounds. -
Updated the
EventDrivenNode
trait to changewait_for_event
from taking an immutable reference to a mutable reference, solving a borrowing issue with thempsc::Receiver
. -
Replaced all incorrect uses of
NodeOutcome::RouteToAction
with the correct single-argument syntax. -
Added the
#[async_trait]
macro to all implementations of async traits. -
Used fully-qualified path syntax to address type inference issues in the
wait_for_event
andid
methods. -
Wrapped the
ChannelEventSource
in atokio::sync::Mutex
to allow safe mutable access from multiple places. -
Fixed the
EventActionExt
trait implementation forDefaultAction
to create proper custom actions. -
Removed unused imports in both crates.
Consequences¶
Positive¶
- The event-driven extensions now compile and work correctly
- The code is more type-safe and follows Rust best practices
- Better error handling with proper error types for event-driven workflows
- Cleaner code with unused imports removed
- Improved consistency between the core, transform, and event APIs
Negative¶
- Small API changes may require updates to existing code that uses these features:
EventDrivenNode::wait_for_event
now requires a mutable reference- The
Action
type parameter now requires theDefault
trait
Neutral¶
- The architecture of the event-driven node system remains fundamentally the same
- Core framework abstractions are unchanged
Future Work¶
- Consider adding more comprehensive documentation for the event-driven capabilities
- Explore adding more event source implementations (e.g., WebSocket, HTTP, etc.)
- Consider adding a more ergonomic API for creating event-driven workflows