V
V
vetsmen2017-08-29 18:15:02
JavaScript
vetsmen, 2017-08-29 18:15:02

How to disable concurrent function call?

How to prevent simultaneous execution of one asynchronous function? That is, there is an asynchronous function asyncFnc(data) {...};
If it is called and has not yet completed, how to prevent its call at this time, but put it in a queue and make sure that this call is executed, but after the first call has been processed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kovalsky, 2017-08-29
@lazalu68

One solution could be any queue implementation.

S
Sergey Sergey, 2017-08-29
@hahenty

Without promises, on old callbacks: https://codepen.io/anon/pen/jLQBNj?editors=0012
Creates a wrapper over the function, calls sequentially, the last argument is a mandatory callback.

M
miki131, 2017-08-30
@miki131

https://github.com/wizcorp/locks

mutex.lock(function () {
  console.log('We got the lock!');
  // do stuff
  mutex.unlock();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question