pub struct Channel { /* private fields */ }Expand description
Just a export struct for the event::Emitter
Implementations§
Source§impl Channel
impl Channel
pub fn new(rt: &Arc<Runtime>) -> Self
Sourcepub fn channel(rt: &Arc<Runtime>, options: &ChannelOptions) -> Self
pub fn channel(rt: &Arc<Runtime>, options: &ChannelOptions) -> Self
create a emit channel to receive message if the message is not received by client, the engine will re-send at the next time interval
Sourcepub fn on_message(
self: &Arc<Self>,
f: impl Fn(&Event<Message>) + Send + Sync + 'static,
)
pub fn on_message( self: &Arc<Self>, f: impl Fn(&Event<Message>) + Send + Sync + 'static, )
Receive act message
Example
use acts::{Engine, Act, Workflow, Vars, Message};
#[tokio::main]
async fn main() {
let engine = Engine::new().start();
let workflow = Workflow::new().with_id("m1").with_step(|step| {
step.with_id("step1").with_act(Act::irq(|act| act.with_key("act1")))
});
engine.channel().on_message(move |e| {
if e.is_irq() {
println!("act message: state={} inputs={:?} outputs={:?}", e.state, e.inputs, e.outputs);
}
});
let exec = engine.executor();
exec.model().deploy(&workflow).expect("fail to deploy workflow");
let mut vars = Vars::new();
vars.insert("pid".into(), "w1".into());
exec.proc().start(
&workflow.id,
&vars,
);
}pub fn on_start( self: &Arc<Self>, f: impl Fn(&Event<Message>) + Send + Sync + 'static, )
pub fn on_complete( self: &Arc<Self>, f: impl Fn(&Event<Message>) + Send + Sync + 'static, )
pub fn on_error( self: &Arc<Self>, f: impl Fn(&Event<Message>) + Send + Sync + 'static, )
pub fn close(&self)
Auto Trait Implementations§
impl Freeze for Channel
impl !RefUnwindSafe for Channel
impl Send for Channel
impl Sync for Channel
impl Unpin for Channel
impl UnsafeUnpin for Channel
impl !UnwindSafe for Channel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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 more