Skip to content

Commit

Permalink
Added suicide call to context and suppress warnings in macro generate…
Browse files Browse the repository at this point in the history
…d code when using Never type
  • Loading branch information
Bathtor committed Oct 16, 2019
1 parent 595a625 commit ef1493d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 4 additions & 1 deletion core/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub trait CoreContainer: Send + Sync {
fn execute(&self) -> ();

fn control_port(&self) -> ProvidedRef<ControlPort>;
//fn actor_ref(&self) -> ActorRef;
fn system(&self) -> KompactSystem {
self.core().system().clone()
}
Expand Down Expand Up @@ -532,6 +531,10 @@ impl<CD: ComponentDefinition + Sized + 'static> ComponentContext<CD> {
pub fn id(&self) -> Uuid {
self.component().id().clone()
}

pub fn suicide(&self) -> () {
self.component().control_port().enqueue(ControlEvent::Kill);
}
}

impl<CD> ActorRefFactory<CD::Message> for ComponentContext<CD>
Expand Down
22 changes: 14 additions & 8 deletions macros/component-definition-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ fn impl_component_definition(ast: &syn::DeriveInput) -> TokenStream2 {
if count >= max_events {
return ExecuteResult::new(count, #i);
}
if let Some(event) = self.#id.dequeue() {
#handle
count += 1;
done_work = true;
#[allow(unreachable_code)]
{ // can be Never type, which is ok, so just suppress this warning
if let Some(event) = self.#id.dequeue() {
#handle
count += 1;
done_work = true;
}
}
}
}
Expand All @@ -89,10 +92,13 @@ fn impl_component_definition(ast: &syn::DeriveInput) -> TokenStream2 {
if count >= max_events {
return ExecuteResult::new(count, #i);
}
if let Some(event) = self.#id.dequeue() {
#handle
count += 1;
done_work = true;
#[allow(unreachable_code)]
{ // can be Never type, which is ok, so just suppress this warning
if let Some(event) = self.#id.dequeue() {
#handle
count += 1;
done_work = true;
}
}
}
})
Expand Down

0 comments on commit ef1493d

Please sign in to comment.