1

for those who know Javascript and IBM BPM, I need to know how to delay the execution of the trigger below, represented by the IBM BPM code this.context.trigger();.

The code is actually working, except for the delay which is not considered in my code.

Can you please help me? Thanks a lot

var _this = this;

function myFunction() {
setTimeout(myFunction, 10000);
_this.context.trigger();
}

myFunction();
GGG
  • 49
  • 1
  • 10
  • 1
    i believe you are mistakenly thinking that setTimeout is a sync function, like sleep in other languages, but in javascript setTimeout is Async and calls its first parameter after a delay of 10000. read my answer for fix – Bamieh Jul 27 '16 at 13:46

4 Answers4

4

I believe you are mistakenly thinking that setTimeout is a sync function, like sleep in other languages, but in javascript setTimeout is Async and calls its first parameter after a delay of 10000

you are calling myFunction outside which calls _this.context.trigger immediately then once every 10000. rewrite your function to this code in order to work.

function myFunction() {
   this.context.trigger();
}
setTimeout(myFunction.bind(this), 10000);
Bamieh
  • 10,358
  • 4
  • 31
  • 52
0

maybe this could work

var _this = this;

function myFunction() {
    _this.context.trigger();
}

setTimeout(myFunction, 10000);
ddb
  • 2,423
  • 7
  • 28
  • 38
0

setTimeout is not a sleep() function. It does not pause execution whenever it is called. It schedules a given callback to be executed after a timeout. The correct usage would be:

function myFunction(){
    // Do something
}

setTimeout(myFunction, 1000) // Call myFunction in 1000 milliseconds
zero298
  • 25,467
  • 10
  • 75
  • 100
0

In IBM BPM if you want to set sleep, then please try below code directly in the server script block.

java.lang.Thread.sleep(milliseconds); (or)

java.lang.Thread.currentThread().sleep(milliseconds);