createTimer() correct syntax?

Hello,

German ohhh jehh :wink:

can please anyone tell me the right syntax of createTimer() function in a rule?
There are different definitions and examples here in the forum and in the documentations:
e.g.
createTimer( condition_expression , [ blank | command_to_call ] )
createTimer( condition_expression ) [ blank | [ command_to_call ]
createTimer( condition_expression ) , [ blank | [ command_to_call ]

Almost all possibilities can be found.
/Ulli

It’s fairly flexible, but your second and third examples can never work - you must have paired brackets.

The Rules DSL is based somewhat on Xtend. Extend has a bunch of “syntatic sugar” built in that lets you leave certain things out or change the definition slightly in certain contexts. I find it frustraiting and annoying and a source for confusion.

The ones that come to mind include:

  • getters and setters can be called as if accessing the data member directly (e.g. MyItem.getState() can become MyItem.state)
  • when the method doesn’t have any arguments, the parens are optional (e.g. myTimer.cancel() can become myTimer.cancel)
  • if the last argument of a method call is a lambda, the lambda can be defined outside of the parens (e.g. createTimer(now.plusSeconds(1), [ | logInfo("test", "test" ]) can become createTimer(now.plusSeconds(1)) [ | logInfo("test", "test" ])

As rossko57 points out, your second example is incorrect and should be

createTimer( condition_expression) [ blank | command_to_call ] 

and your third example is just wrong. You would get a syntax error if you put in that extraneous comma.

Another couple of comments:

  • condition_expression isn’t really a condition, it’s the date and time when the Timer will run the code in the lambda.
  • command_to_call can be any number of lines of code.

yes, it’s a little bit special :wink:

find it frustraiting and annoying and a source for confusion

This exactly happens to me, a C / C++ programmer who almost 35 years trying to make computers to do what the programmer wants.