A
A
Aleksandr2020-04-28 15:57:54
JavaScript
Aleksandr, 2020-04-28 15:57:54

Triggers how to prevent the re-execution of a function until it completes?

For example, a trigger fires, a function starts, let's say the function will perform some
complex calculations for 1-2 seconds, the user has time to call the same function again before the end of the called function.

Is there a solution for the scenario if the trigger called the function, then at the beginning of the STOP function, we execute the function for the trigger and at the end of the function we TURN ON the trigger?

Simply put, how to prevent a function call from a trigger again until it has completed its actions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-04-28
@rpsv

Use blocking: guaranteed to run only 1 time at the time of blocking:

var blocked = false;
var action = function() {
   if (blocked === true) {
      return;
   }
   blocked = true;
   // выполнение
   blocked = false;
}
action();
action();
action();
action();
action();
action();
action();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question