Skip to main content
13-Aquamarine
Jan 11, 2024 10:39 AM UTC
Solved

How to run code async in a ThingWorx service

Hi,

I am creating a service that fetches data from an external api with subsequent actions that needs to be run in a certain order. As an api call needs to finish, I wonder how to run code asyncroniously in a thingworx service?

 

I tried to write an async function, but I got the error in the image bellow, writing use 'esversion: 8' did not work.

 

Screenshot 2024-01-11 113657.png

14-Alexandrite
Jan 11, 2024 6:09 PM UTC

Will running the service itself as async will not work for you? From the service, you can either use property set event or event subscription to trigger other processes. If the other stuffs are not heavy/long you can probably put to same service.

3 replies

Rocko
19-Tanzanite
Jan 11, 2024 2:03 PM UTC

As of now you can't use it. TWX uses Rhino 1.7,11 (or so) and does not allow for the async feature. https://mozilla.github.io/rhino/compat/engines.html

 

Alternatives are Web hooks with the other system pushing the result into Thingworx or that you are polling regularly for the result with a request key.

Translate
22-Sapphire I
Jan 11, 2024 6:02 PM UTC

From what you are saying, perhaps you can use the end of the API call to invoke an event/subscription to then start the next set of services.

Translate
14-Alexandrite
Jan 11, 2024 6:09 PM UTC

Will running the service itself as async will not work for you? From the service, you can either use property set event or event subscription to trigger other processes. If the other stuffs are not heavy/long you can probably put to same service.

Translate