Search code examples
javascriptibm-bpm

IBM BPM - Javascript trigger delay


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();

Solution

  • 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);