AsyncScriptResult
. The concept of an AsyncScriptResult
is modelled after how promises work in JavaScript.AsyncScriptResult.then
AsyncScriptResult
StackState will automatically wait for the actual result to resolve. If however you want to continue your script with the resolved result of an AsyncScriptResult
you must use the .then
method..then
method expects a Groovy closure. The closure will execute as soon as the result is received. This lambda function can work with the result and return either a new AsyncScriptResult
or a simple (synchronous) result.it
keyword is default Groovy keyword that you do not need to define a variable in which you receive your result. You might see this being used in our examples.asyncFn1
are passed to asyncFn2
, then the results of asyncFn2
in turn are passed to asyncFn3
.AsyncScriptResult
are automatically flattened when returned from a .then
call. For example:asyncFn2
and asyncFn3
.thenCollect
AsyncScriptResult
.ScriptApi.asyncFn1()
return an AsyncScriptResult
that contains the list [1,2,3]
, this can be transformed to [2,3,4]
in the following way:.then { it.collect { ... }}
, which makes it possible to rewrite the above as:thenInject
AsyncScriptResult
can be automatically reduced when returned. For example:asyncFn1
returns a list, then subsequent thenInject
call can accumulate the result, in this case using summation.AsyncScriptResult
. See example below:AsyncScriptResult
. This can be achieved using catchError
function. For example:catchError
gets automatically flattened just like .then
call.