pub struct ChannelEvent { /* private fields */ }Expand description
Builder for registering event handlers with filtering.
Use this to subscribe to specific events from the channel:
ⓘ
ChannelEvent::channel(channel, ChannelOptions::with_pid(pid))
.on_complete(|pid| println!("Process {} completed", pid))
.on_error(|e| println!("Error: {:?}", e))
.on_log(|log| println!("Log: {}", log.content));Implementations§
Source§impl ChannelEvent
impl ChannelEvent
Sourcepub fn channel(channel: Arc<Channel>, options: ChannelOptions) -> Self
pub fn channel(channel: Arc<Channel>, options: ChannelOptions) -> Self
Creates a new event subscriber with the given options.
Examples found in repository?
examples/simple/main.rs (line 16)
3fn main() {
4 let engine = EngineBuilder::new().build().unwrap();
5
6 // Launch the engine
7 engine.launch();
8
9 let text = include_str!("./workflow.json");
10
11 let workflow_model = WorkflowModel::from_json(text).unwrap();
12
13 let process = engine.build_workflow_process(&workflow_model).unwrap();
14 let pid = process.id();
15
16 ChannelEvent::channel(engine.channel(), ChannelOptions::with_pid(pid.to_owned())).on_complete(move |pid| {
17 println!("Workflow completed, pid: {}", pid);
18 });
19
20 ChannelEvent::channel(engine.channel(), ChannelOptions::with_pid(pid.to_owned())).on_error(move |e| {
21 println!("Workflow failed: {:?}", e);
22 });
23
24 // Start the workflow process
25 process.start();
26
27 loop {
28 if process.is_complete() {
29 break;
30 }
31 std::thread::sleep(std::time::Duration::from_millis(100));
32 }
33
34 let outputs: serde_json::Value = process.get_outputs().into();
35 println!("Outputs: {:#?}", outputs);
36}Sourcepub fn on_complete(&self, f: impl Fn(String) + Send + Sync + 'static)
pub fn on_complete(&self, f: impl Fn(String) + Send + Sync + 'static)
Registers a handler for workflow completion events.
Examples found in repository?
examples/simple/main.rs (lines 16-18)
3fn main() {
4 let engine = EngineBuilder::new().build().unwrap();
5
6 // Launch the engine
7 engine.launch();
8
9 let text = include_str!("./workflow.json");
10
11 let workflow_model = WorkflowModel::from_json(text).unwrap();
12
13 let process = engine.build_workflow_process(&workflow_model).unwrap();
14 let pid = process.id();
15
16 ChannelEvent::channel(engine.channel(), ChannelOptions::with_pid(pid.to_owned())).on_complete(move |pid| {
17 println!("Workflow completed, pid: {}", pid);
18 });
19
20 ChannelEvent::channel(engine.channel(), ChannelOptions::with_pid(pid.to_owned())).on_error(move |e| {
21 println!("Workflow failed: {:?}", e);
22 });
23
24 // Start the workflow process
25 process.start();
26
27 loop {
28 if process.is_complete() {
29 break;
30 }
31 std::thread::sleep(std::time::Duration::from_millis(100));
32 }
33
34 let outputs: serde_json::Value = process.get_outputs().into();
35 println!("Outputs: {:#?}", outputs);
36}Sourcepub fn on_error(&self, f: impl Fn(&Event<Message>) + Send + Sync + 'static)
pub fn on_error(&self, f: impl Fn(&Event<Message>) + Send + Sync + 'static)
Registers a handler for workflow error events.
Examples found in repository?
examples/simple/main.rs (lines 20-22)
3fn main() {
4 let engine = EngineBuilder::new().build().unwrap();
5
6 // Launch the engine
7 engine.launch();
8
9 let text = include_str!("./workflow.json");
10
11 let workflow_model = WorkflowModel::from_json(text).unwrap();
12
13 let process = engine.build_workflow_process(&workflow_model).unwrap();
14 let pid = process.id();
15
16 ChannelEvent::channel(engine.channel(), ChannelOptions::with_pid(pid.to_owned())).on_complete(move |pid| {
17 println!("Workflow completed, pid: {}", pid);
18 });
19
20 ChannelEvent::channel(engine.channel(), ChannelOptions::with_pid(pid.to_owned())).on_error(move |e| {
21 println!("Workflow failed: {:?}", e);
22 });
23
24 // Start the workflow process
25 process.start();
26
27 loop {
28 if process.is_complete() {
29 break;
30 }
31 std::thread::sleep(std::time::Duration::from_millis(100));
32 }
33
34 let outputs: serde_json::Value = process.get_outputs().into();
35 println!("Outputs: {:#?}", outputs);
36}Sourcepub fn on_event(&self, f: impl Fn(&Event<Message>) + Send + Sync + 'static)
pub fn on_event(&self, f: impl Fn(&Event<Message>) + Send + Sync + 'static)
Registers a handler for all matching events.
Sourcepub fn on_log(&self, f: impl Fn(&Event<Log>) + Send + Sync + 'static)
pub fn on_log(&self, f: impl Fn(&Event<Log>) + Send + Sync + 'static)
Registers a handler for log events.
Sourcepub fn on_event_async<F>(&self, f: F)
pub fn on_event_async<F>(&self, f: F)
Registers an async handler for all matching events.
Trait Implementations§
Source§impl Clone for ChannelEvent
impl Clone for ChannelEvent
Source§fn clone(&self) -> ChannelEvent
fn clone(&self) -> ChannelEvent
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ChannelEvent
impl !RefUnwindSafe for ChannelEvent
impl Send for ChannelEvent
impl Sync for ChannelEvent
impl Unpin for ChannelEvent
impl !UnwindSafe for ChannelEvent
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request