MaestroThe UI design product. | Form Builder Platform Developer | 19.05 This feature was introduced in 19.05.
Journey Maestro allows you to build user experiences using forms that interact with a Manager server by invoking remote services. These services run asynchronously - meaning that it will take time to execute them, and you will be notified when (or in some cases, if) a service responds. Occasionally, internal methods within Maestro are also executed asynchronously.
When you design these methods, you need to:
The basic mechanism for handling asynchronous events is to use callback functions, which is a function that is called when the asynchronous invocation returns. This works, but it makes source code harder to understand.
A more modern approach is to use a promise, which is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. For more information, see Using promises.
Maestro uses promises internally. Also, you don't need to create a promise in Maestro, because asynchronous calls already return promises - you just need to chain them by wrapping method invocations inside a series of then(...)
method calls.
When you write a promise, you should try to incorporate the following patterns:
Let's look at each pattern in details.
You should always use chaining with promises. Nesting promises will result in the code that is very difficult to read and understand.
A good example of chaining looks like this:
invoke1(...).then(function (resultOfInvoke1) {
return invoke2(...);
}).then(function (resultOfInvoke2) {
return invoke3(...);
}).then(function (resultOfInvoke3) {
return invoke4(...);
}).catch(function (err) {
console.log(err);
});
Each function should return a value, which can be one of the following:
then()
clause will execute once the promise is resolvedthen()
clause will execute immediately when the function returnsthrow new Error('Something Bad'); // throwing a synchronous error!
It's important to remember that a parameter of the next function will be a result of the previous one. Or put the other way - the result that you return in the current function will be the input parameter of the next one. This is shown clearly in the naming convention of the example above - the function is called invoke2
, and the next function takes as its parameter resultOfInvoke2
.
If you need to add an extra step to the sequence of invocations, you simply need to copy and paste the following two lines:
}).then(function (resultOfInvoke2) {
return invoke3(...);
You always need to have a catch clause at the end as you never know whether something unexpected will happen or not.
Next, learn about pre-submit validation.