Skip to main content
13-Aquamarine
January 11, 2024
Solved

How to run code async in a ThingWorx service

  • January 11, 2024
  • 2 replies
  • 1636 views

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

Best answer by Bikash_Panda

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.

2 replies

Rocko
19-Tanzanite
January 11, 2024

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.

22-Sapphire I
January 11, 2024

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.

14-Alexandrite
January 11, 2024

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.