Skip to content

Commit

Permalink
Forwarding (#61)
Browse files Browse the repository at this point in the history
* Added forwarding API for messages

* Add tests for forwarding API
  • Loading branch information
Bathtor authored Apr 27, 2020
1 parent dccaa25 commit a0322a4
Show file tree
Hide file tree
Showing 8 changed files with 493 additions and 244 deletions.
33 changes: 31 additions & 2 deletions core/src/actors/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,37 @@ impl ActorPath {
}
}

// TODO
//pub fn forward(&self, serialized_message: NetMessage);
/// Forwards the still serialised message to this path without changing the sender
///
/// This can be used for routing protocls where the final recipient is supposed to reply
/// to the original sender, not the intermediaries.
pub fn forward_with_original_sender<D>(
&self,
mut serialised_message: NetMessage,
dispatcher: &D,
) -> ()
where
D: Dispatching,
{
serialised_message.receiver = self.clone();
let env = DispatchEnvelope::ForwardedMsg {
msg: serialised_message,
};
dispatcher.dispatcher_ref().enqueue(MsgEnvelope::Typed(env));
}

/// Forwards the still serialised message to this path replacing the sender with the given one
pub fn forward_with_sender<CD>(&self, mut serialised_message: NetMessage, from: &CD) -> ()
where
CD: ComponentDefinition + Sized + 'static,
{
serialised_message.receiver = self.clone();
serialised_message.sender = from.actor_path();
let env = DispatchEnvelope::ForwardedMsg {
msg: serialised_message,
};
from.dispatcher_ref().enqueue(MsgEnvelope::Typed(env));
}

/// Returns a temporary combination of an [ActorPath](ActorPath)
/// and something that can [dispatch](Dispatching) stuff
Expand Down
Loading

0 comments on commit a0322a4

Please sign in to comment.