Skip to main content

SignalReceiver

Trait SignalReceiver 

Source
pub trait SignalReceiver {
    // Required methods
    fn on_signal(&mut self, signal: &Signal) -> SignalResponse;
    fn abort(&mut self);
}
Expand description

Signal receiver for human control.

All entities must respond to signals because “Human is Superpower” - humans can always interrupt.

§Signal Priority

Signals are the highest priority messages in ORCS. They must be processed immediately, even during active work.

§Required Responses

SignalExpected Response
VetoAbort + call abort()
Cancel (in scope)Abort or Handled
Cancel (out of scope)Ignored
PauseHandled + change state
ResumeHandled + resume work

§Example

use orcs_component::{SignalReceiver, Status};
use orcs_event::{Signal, SignalResponse};

struct Worker {
    status: Status,
}

impl SignalReceiver for Worker {
    fn on_signal(&mut self, signal: &Signal) -> SignalResponse {
        if signal.is_veto() {
            self.abort();
            SignalResponse::Abort
        } else if signal.is_global() {
            // Global signals we can't handle
            SignalResponse::Ignored
        } else {
            SignalResponse::Handled
        }
    }

    fn abort(&mut self) {
        self.status = Status::Aborted;
        // Clean up resources, cancel pending work, etc.
    }
}

Required Methods§

Source

fn on_signal(&mut self, signal: &Signal) -> SignalResponse

Handle an incoming signal.

Called for every signal that reaches this entity. Must check signal scope to determine relevance.

§Returns
  • Handled: Signal was processed
  • Ignored: Signal not relevant (out of scope)
  • Abort: Entity is stopping due to signal
Source

fn abort(&mut self)

Immediate abort.

Called when a Veto signal is received. Must stop all work immediately and clean up.

§Contract

After abort() is called:

  • No more work should be performed
  • Resources should be released
  • Status should become Aborted

Implementors§