Skip to content

Toro Cloud Dev Center


examples package: Using asynchronous Gloop Invoke steps

Asynchronous Gloop invoke steps are Gloop steps that invoke the target service in a separate thread, enabling the main service to continue to the next step without having to wait for the asynchronous step to finish first. Asynchronous invoke steps appear with no output in the Mapper (since they run in a separate thread and the outputs aren't used), and they appear in the service editor with green thread badges on the top right-hand corner (as shown below on lines 3-6).

Invoke steps with the asynchronous badge

Invoke steps with the asynchronous badge

The examples package demonstrates the use of asynchronous steps in the
asyncStep.AsyncStepDemo.gloop service.

Related articles

Please see the following articles for more information:

Try it!

In the Navigator, expand the examples package and navigate to the code folder, then expand the asyncStep package. This package contains three files, as shown below:

1
2
3
4
5
6
7
8
9
examples
├── ...
└── code
    └── asyncStep
        ├── util
        │   ├── Countdown.gloop
        │   ├── GetPackagePropertyAsync.gloop
        │   └── SleepingThread.gloop
        └── AsyncStepDemo.gloop

Running the AsyncStepDemo.gloop service will produce an output similar to the logs below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
INFO  [Martini] asyncStepDemo: This step is going to make the current thread sleep for 2 seconds
INFO  [Martini] asyncStepDemo: Going to sleep now...
INFO  [Martini] exampleProperty is: example value
INFO  [Martini] Package is: ESBPackage [name=examples]
INFO  [Martini] countdown: Current count is 0
INFO  [Martini] countdown: Current count is 1
INFO  [Martini] countdown: Current count is 2
INFO  [Martini] countdown: Current count is 3
INFO  [Martini] countdown: Current count is 4
INFO  [Martini] countdown: Current count is 5
INFO  [Martini] countdown: Current count is 6
INFO  [Martini] countdown: Current count is 7
INFO  [Martini] countdown: Current count is 8
INFO  [Martini] countdown: Current count is 9
INFO  [Martini] asyncStepDemo: The thread has now woken. If the service was executed correctly over HTTP, the rest of the service would have run while this thread was asleep.
INFO  [Martini] countdown: Current count is 10
INFO  [Martini] countdown: Current count is 11
INFO  [Martini] countdown: Current count is 12
...
INFO  [Martini] countdown: Current count is 23
INFO  [Martini] countdown: Current count is 24
INFO  [Martini] countdown: Finished counting

Explanation

The AsyncStepDemo.gloop service demonstrates how Gloop behaves when it is asked to invoke services asynchronously. Gloop allows concurrent and invoke steps to run asynchronously.

Not really asynchronous when debugging

Please take note that in order to make debugging services easier in Martini, asynchronous steps are executed synchronously when debugging. If you'd like to test asynchronous steps in an asynchronous fashion, the Invoke in Browser (or Invoke in HTTP Client) option should be used when calling the service. To do this, right-click the service and select Invoke In Browser (or Invoke in HTTP Client) from the context menu.

Invoke in Browser option as seen in context menu

Invoke in New Tab option as seen in context menu

In Martini Desktop, you can also drag and drop the service to the HTTP Client as shown here.