Pause execution of javascript (or JAVA)

kmll's icon

Is there a good way of pausing execution of a javascript? I want to send one message to outlet 0, then wait e.g 300ms and then send another message to outlet 1. Is this a good idea or is it generally bad practise to halt execution. I guess it would be ok to do this in JAVA by using Thread.sleep(300);? Maybe JAVA it is a better route to do this?

Andrew Pask's icon
kmll's icon

Thanks for the advise! I looked into using the suggestions and found an issue with it.

tsk = new Task(repeater_function, this);
tsk.interval = 3000; // every 3 sec

function repeater_function() {
post("This is repeater_function",arguments.callee.task.iterations);
}

The issue is that the first time repeater_function runs it runs immediately and then on subsequent runs it waits the three seconds, and it is only the initial wait I need.

EDIT:
I came to think of a hack that I can test in the repeater_function that if iterations = 1 then do nothing og if iterations is 2 then I do the work.. I guess it is a hack and not elegant and I still am not sure why the developers have made the decision to ignore the wait on the first run..well well. It works anyway:) - Thanks!