Skip to content

Home

Introduction

Development

IDEs

Services

API Explorer

Releases

Release notes

Martini Runtime

Martini Desktop

Martini Online

Feature requests

Bug reports

examples package: Using asynchronous Gloop steps

Asynchronous steps are Gloop steps that run in a separate thread, enabling the service to continue to the next step without having to wait for the asynchronous step to finish first.

The examples package demonstrates the use of the Asynchronous property to allow for asynchronous steps via the AsyncStepDemo.gloop service.

Related articles

Please see the following articles for more information:

Try it!

Under the Navigator, expand the examples package and navigate to the code folder. Afterwards, look for the asyncStep package. This package contains three files, 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 that of below:

AsyncStepDemo.gloop's console outputs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
24/04/19 16:11:00.379 INFO  [Martini] asyncStepDemo: This step is going to make the current thread sleep for 2 seconds
24/04/19 16:11:00.383 INFO  [Martini] asyncStepDemo: Going to sleep now...
24/04/19 16:11:00.805 INFO  [Martini] exampleProperty is: example value
24/04/19 16:11:01.009 INFO  [Martini] Package is: ESBPackage [name=examples]
24/04/19 16:11:01.337 INFO  [Martini] countdown: Current count is 0
24/04/19 16:11:01.494 INFO  [Martini] countdown: Current count is 1
24/04/19 16:11:01.648 INFO  [Martini] countdown: Current count is 2
24/04/19 16:11:01.803 INFO  [Martini] countdown: Current count is 3
24/04/19 16:11:01.959 INFO  [Martini] countdown: Current count is 4
24/04/19 16:11:02.113 INFO  [Martini] countdown: Current count is 5
24/04/19 16:11:02.268 INFO  [Martini] countdown: Current count is 6
24/04/19 16:11:02.423 INFO  [Martini] countdown: Current count is 7
24/04/19 16:11:02.577 INFO  [Martini] countdown: Current count is 8
24/04/19 16:11:02.731 INFO  [Martini] countdown: Current count is 9
24/04/19 16:11:02.809 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.
24/04/19 16:11:02.885 INFO  [Martini] countdown: Current count is 10
24/04/19 16:11:03.039 INFO  [Martini] countdown: Current count is 11
24/04/19 16:11:03.193 INFO  [Martini] countdown: Current count is 12
...
24/04/19 16:11:04.881 INFO  [Martini] countdown: Current count is 23
24/04/19 16:11:05.035 INFO  [Martini] countdown: Current count is 24
24/04/19 16:11:05.316 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 due to some limitations in the Martini debugger, 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 New Tab) option should be used when calling the Gloop service. To do this, right-click the service and select Invoke In Browser (or Invoke in New Tab) from the context menu.

Invoke in Browser option as seen in context menu

Invoke in New Tab option as seen in context menu