Skip to main content
1-Visitor
December 19, 2016
Solved

Does ThingWorx has full support of setTimeout() service?

  • December 19, 2016
  • 10 replies
  • 6513 views

Hi,

Everytime I use setTimeout() function in all the option it can be used it throws an exeption: ReferenceError: "setTimeout" is not defined.

I noticed also that the function inside the setTimeout DOES run, so I need to use try and catch in all the places.

I wonder whether I use the wrong syntax for setTimeout, I think I tried them all


setTimeout(nameOfFunction(),1000);

setTimeout("nameOfFunction()",1000);

setTimeout(nameOfFunction,1000);

setTimeout("nameOfFunction",1000);

setTimeout(function {nameOfFunction()},1000);

setTimeout(new function {nameOfFunction()},1000);


and some other options.

I really don't want to use pause.

It there any suggestion?


Best answer by CarlesColl

I don't think so, neither the other way ( saying it has it ). Server Side Javascript runs on a RHINO javascript engine, you can do a search on that mater ( I did it and it says there isn't setTimeout - it shows up some alternative ways that you may give it a shot... ).

10 replies

1-Visitor
December 19, 2016

There's no setTimeout service, neither you can use pause for it, you should build a queue system in order to do SetTimeout alike.

aelgov1-VisitorAuthor
1-Visitor
December 19, 2016

There is!

It is working but it throws an exception.

The service is getting executed.

1-Visitor
December 19, 2016

Hi Assaf, no there isn't.

It throws and error becouse it doesn't exists, but of course if you execute something like setTimeout(aFunction(),1000) it will execute aFunction() before trying to execute setTimeout, for instance you can think that this is working as setTimeout but it isn't:

function TesTimedService() {

    logger.info("LOG MESSAGE");

}

try{

    setTimeout(TesTimedService(),1000);

}catch(err) {

}

Standard Javascript setTimeout works receiving a function as a parameter, which doesn't execute anything in TW server side javascript:

try{

setTimeout(function TesTimedService() { logger.info("LOG MESSAGE 2");},1000);

}catch(err) {

}

From previous code which would be correct setTimeout call you don't get "LOG MESSAGE 2" on the logs as it's never executed.

aelgov1-VisitorAuthor
1-Visitor
December 19, 2016

What you just explained make sense, but I saw code of TW using this setTimeout function.

1-Visitor
December 19, 2016

If it's UI code ( extensions ) you may use at it's running at browser side, but not for the Server Side Javascript.