Flow
The flow object provides a mechanism to invoke other flows. This allows some flows to become superflows connecting multiple flows together. Flows from other applications may also be invoke in this fashion.
Shared functionality
You can use the include(...)
method to include code from a MODULE
typed flow. This is great if you have some code that you want to share between multiple flows.
The code in the module flow can export its functionality by assigning variables to the global exports
object. See the example below.
Parameters
name
the name or subject of the module to include
Examples
We’ll define a handy math
module (given the subject
= math
):
var times = function(a, b) {
return a*b;
}
var plus = function(a, b) {
return a+b;
}
var bigNumber = 10000;
exports.times = times;
exports.plus = plus;
exports.bn = bigNumber;
and this can then be used in another flow:
var math = Flow.include('math');
var ten = math.times(2, 5);
Run flow
Run another flow with the run(...)
method. You provide the input to the flow and will get the outputs of the flow.
Parameters
name
the name, subject or id of the flow to run - if there are 0 or more than 1 flow with this name anError
will be thrownenvironment
is a JavaScript object containing the input to the flow. Each property on the object will be mapped to an input. Currently only string values are supported. Inputs are accessed in the running flow withInputs["<inputname>"]
e.g.Inputs["myinput"]
or simply<inputname>
e.g.myinput
(if the<inputname>
is a valid JavaScript identifier).session
a session selector (see below)options
(optional) which can include;allowLaunch
(bool) allow Manatee to launch the application, default istrue
allowVirgin
(bool) allow Manatee to run the flow before the state of the application has been synchronised
Disambiguation
Since it is possible and valid to have flows in multiple apps with the same name, it can be ambiguous which flow should be chosen by Flow.run
. If flows called ExampleFlow
exist in apps A and B and a flow on app A runs Flow.run('ExampleFlow')
, manatee will always prefer the matching flow from the same app (A) as the calling flow.
Note that if ExampleFlow
exists in apps B and C and a flow in app A calls Flow.run('ExampleFlow')
, you can’t be sure which flow is called. In such cases you can use the subject or id of the flow as the first argument instead - or rename one of the colliding flows.
Examples
var result = Flow.run("MyOtherFlow", { "inputA": "AAA", "inputB": "BBB" });
// "MyOtherFlow" will now get executed, the inputs may be accessed via e.g. Inputs["inputA"] in "MyOtherFlow"
var outputC = result.outputC; // providing "MyOtherFlow" has a defined output called "outputC"
It is possible to chain flows like:
var result = Flow.run("RunLast", Flow.run("RunFirst", {}));
Run a flow only if the application is already running and connected to Manatee:
var result = Flow.run("RunThisOnlyIfAppIsRunning", {}, null, { allowLaunch: false });
Flow.run
to run flows in another session
In order to run a flow in another session you need to provide a third argument to Flow.run
. This “session selector” argument can either be a function
acting as a predicate on the states of the sessions or a an object that contains keys and values to match.
Using a predicate
We’ll assume we have the following sessions currently available.
- Session 1 with app A (instance 1) has the following state;
s1 = v1
. - Session 2 with app A (instance 2) has the following state;
s1 = v2
.
If we want to run the flow “foo” in session 2 then we do:
Flow.run("foo", null, function(state) { return state["s1"] === "v2"; });
Using a key-value match
Using the same sessions described above we can match session 2 again using a the key-value match:
Flow.run("foo", null, {"s1": "v2"});
The key-value matcher will also create the session if it does not exist - this will not happen using the predicate approach.
Stop the current flow
Use the stop()
method to stop a running flow gracefully.
Flow.stop();