Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mediator

In-process messaging for Pudu: requests, notifications, streams, pipeline behaviors, processors, and exception handling

0.1.0Apache-2.01

InstallClose

Open.pudu

Pudu48 lines2.3 KB

GitHub ↗
1/** @Mediator.Open.Seam — components that apply to every kind of message */2module PuduLangMediator.Open34import PuduLangMediator.Context as Context5import PuduLangMediator.Message as Message6import PuduLangMediator as Messaging7import PuduLangMediator.Request as Request8import PuduLangMediator.Stream as Stream910/** @Mediator.Open.Behavior — wraps the pipeline of every request */11export trait Behavior {12  /// Runs `next`, or answers in its place, for any request.13  fn handleRequest[Q, R, E](self: &Self, request: &Q, info: &Message.Info, context: Context.Context, next: Request.Next[R, E]) -> Messaging.Outcome[R, E]14}1516/** @Mediator.Open.PreProcessor — runs before the handler of every request */17export trait PreProcessor {18  /// `Ok` to let the request continue; a failure stops it.19  fn beforeRequest[Q, E](self: &Self, request: &Q, info: &Message.Info, context: Context.Context) -> Messaging.Outcome[(), E]20}2122/** @Mediator.Open.PostProcessor — runs after the handler of every request */23export trait PostProcessor {24  /// `Ok` to let the response through; a failure replaces it.25  fn afterRequest[Q, R, E](self: &Self, request: &Q, response: &R, info: &Message.Info, context: Context.Context) -> Messaging.Outcome[(), E]26}2728/** @Mediator.Open.ExceptionAction — observes the failure of every request */29export trait ExceptionAction {30  /// Observes a failure that keeps propagating after every action has run.31  fn onFailure[Q, E](self: &Self, request: &Q, failure: &Messaging.Failure[E], info: &Message.Info, context: Context.Context) -> ()32}3334/** @Mediator.Open.NotificationHandler — receives every notification */35export trait NotificationHandler {36  /// Receives one notification of any kind.37  fn handleNotification[N, E](self: &Self, notification: &N, info: &Message.Info, context: Context.Context) -> Messaging.Outcome[(), E]38}3940/** @Mediator.Open.StreamBehavior — wraps the pipeline of every stream */41export trait StreamBehavior {42  /// Runs `next` with this sink or one wrapping it, or answers in its place, for any stream.43  fn handleStream[Q, T, E](self: &Self, request: &Q, info: &Message.Info, context: Context.Context, sink: Stream.Sink[T], next: Stream.Next[T, E]) -> Messaging.Outcome[(), E]44}4546/** @Mediator.Open.Listener — an open notification handler and the name it is reported by */47export type Listener = { name: Str, handler: dynamic NotificationHandler }48