responsibility_chain library

Provides a base for implementing asynchronous responsibility chains in Dart.

The ResponsibilityChain and ResponsibilityChainWithArgs classes provide the ability to chain handlers using the method cascading.

Use ResponsibilityChain.node to chain ResponsibilityNode class ancestors and ResponsibilityChain.funcNode to chain the functional handler nodes.

  • Functional handler nodes can utilize simple logic.
  • Inherit from ResponsibilityNode to implement more complex abstractions.

Classes

ChainResult<R>
A monad that wraps the result of ResponsibilityChain handler node execution.
IResponsibilityNodeBase<R, A>
An alternative way to declare responsibility node handlers - implement IResponsibilityNode and treat its objects as regular IResponsibilityNodes.
ResponsibilityChain<R>
A class providing the functionality for chaining responsibility handler nodes together and controlling the responsibility distribution between the linked nodes. The orElse function returns the value that should be returned when none of the responsibility handlers succeed to return the result.
ResponsibilityChainWithArgs<R, A>
In contrast to the ResponsibilityChain, this class allows to pass the argument of type A to its handle method. This argument will be passed to every handler node in the chain.

Typedefs

IResponsibilityNode<R, A> = FutureOr<ChainResult<R>> Function(A args)
A typedef representing a handler (responsibility node) that takes args of type A and returns a Future<ChainResult> or ChainResult itself with the type parameter of R. Calling this method should either return a FutureOr<ChainResult<R>>, or throw an exception. Throwing an exception will have the same effect as returning a ChainResult.failure.