Mercy
Flow control library focused on readability, convenience & analytics.
Table of Contents
Introduction
Tired of...
- Entering into a new code base with no information? unknown execution paths?
- Juggling asynchronous operations with flow control optimization?
- Building a mock server because your upstream is often unstable or offline?
What if there exists a way to...
- Allow you to create a simple structure that clearly describes your application and/or business logic lifecycle?
- Promote sharing by offering deferred execution for all constructed flows?
- Automatically instrument analytics for all execution paths?
This is Mercy
; A hybrid API between Async
and Joi
API
See the detailed API Reference.
Usage
Usage is a two steps process. First, a flow must be constructed:
const echo = { return ; }; const flow1 = Mercy // series - Rest () notationconst flow2 = Mercy; // series - Array [] notationconst flow3 = Mercy; // parallel - Object {} notationconst flow4 = Mercy;
Note that mercy flow objects are immutable which means every additional rule added (e.g. .timeout(1000)
) will return a
new flow object.
Then the flow is executed:
Mercy; // Mercy Flows can directly call `flow.execute(data, callback)`. flow;
When passing a non-type flow object, the module converts it internally to a flow() type equivalent:
// The following is equivalentconst foo = { return };const callback = { console; // result is [data object]}; const flow1 = foo ;const flow2 = Mercy; Mercy;Mercy;
Examples
Building basic flows
const Mercy = ; const noop = { return ; };const echo = { return ; };
Empty
const empty = Mercy;
Series
// Series automatically propagates a flow's input/output to proceeding tasklet series = Mercy; // Rest () notationlet series = Mercy; // Array [] notationlet series = Mercy; // Object {} notation Mercy;
Parallel
// Parallel does not propagate flow's input.// Similar to `auto()`, you must specify a `final()` task to select results.const parallel = Mercy; Mercy;
Auto
// Auto does not propagate input. However, it does make use of dependency injection.// Similar to `parallel()`, you must specify a `final()` task to select results.const auto = Mercy; Mercy;
Test case usage
const Mercy = ;