Skip to content

Commit

Permalink
Updated Context to contain an optional Supervisor and removed "is_sys…
Browse files Browse the repository at this point in the history
…tem_supervisor" from SupervisorRef.
  • Loading branch information
r3v2d0g committed Nov 11, 2019
1 parent 63babc6 commit 18a81d2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
3 changes: 1 addition & 2 deletions bastion/src/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ impl Children {

let child_ref = ChildRef::new(id.clone(), sender.clone());
let children = self.as_ref();
// FIXME
let supervisor = self.bcast.parent().clone().into_supervisor().unwrap();
let supervisor = self.bcast.parent().clone().into_supervisor();

let state = ContextState::new();
let state = Qutex::new(state);
Expand Down
10 changes: 3 additions & 7 deletions bastion/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct BastionContext {
id: BastionId,
child: ChildRef,
children: ChildrenRef,
supervisor: SupervisorRef,
supervisor: Option<SupervisorRef>,
state: Qutex<ContextState>,
}

Expand All @@ -38,7 +38,7 @@ impl BastionContext {
id: BastionId,
child: ChildRef,
children: ChildrenRef,
supervisor: SupervisorRef,
supervisor: Option<SupervisorRef>,
state: Qutex<ContextState>,
) -> Self {
BastionContext {
Expand Down Expand Up @@ -172,11 +172,7 @@ impl BastionContext {
/// [`SupervisorRef`]: supervisor/struct.SupervisorRef.html
/// [`Bastion::children`]: struct.Bastion.html#method.children
pub fn supervisor(&self) -> Option<&SupervisorRef> {
if self.supervisor.is_system_supervisor() {
None
} else {
Some(&self.supervisor)
}
self.supervisor.as_ref()
}

/// Tries to retrieve asynchronously a message received by
Expand Down
14 changes: 2 additions & 12 deletions bastion/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ pub struct Supervisor {
pub struct SupervisorRef {
id: BastionId,
sender: Sender,
// Whether the supervisor referenced was started by
// the system (in which case, users shouldn't be able
// to get a reference to it).
is_system_supervisor: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -195,9 +191,8 @@ impl Supervisor {
// TODO: clone or ref?
let id = self.bcast.id().clone();
let sender = self.bcast.sender().clone();
let is_system_supervisor = self.is_system_supervisor;

SupervisorRef::new(id, sender, is_system_supervisor)
SupervisorRef::new(id, sender)
}

/// Creates a new supervisor, passes it through the specified
Expand Down Expand Up @@ -764,11 +759,10 @@ impl Supervisor {
}

impl SupervisorRef {
pub(crate) fn new(id: BastionId, sender: Sender, is_system_supervisor: bool) -> Self {
pub(crate) fn new(id: BastionId, sender: Sender) -> Self {
SupervisorRef {
id,
sender,
is_system_supervisor,
}
}

Expand Down Expand Up @@ -1054,10 +1048,6 @@ impl SupervisorRef {
self.send(msg).map_err(|_| ())
}

pub(crate) fn is_system_supervisor(&self) -> bool {
self.is_system_supervisor
}

pub(crate) fn send(&self, msg: BastionMessage) -> Result<(), BastionMessage> {
self.sender
.unbounded_send(msg)
Expand Down

0 comments on commit 18a81d2

Please sign in to comment.