0

I want to implement a job queue with concurrency control in JavaScript. I am not able to understand how to implement it. The use case for the job queue is that function will be pushed in the queue and queue has to execute them one at a time and return the data that is returned by that function. Functions can be async also.

braaterAfrikaaner
  • 1,072
  • 10
  • 20
Rishab Jain
  • 269
  • 4
  • 16
  • You should take a look at [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) – Titus Feb 10 '18 at 19:01
  • I am not sure how to use them. – Rishab Jain Feb 10 '18 at 19:04
  • You can use that to chain async functions, establish a happened-before relation. By the way *concurrency control* doesn't make sense since JavaScript is kind of single threaded. – Titus Feb 10 '18 at 19:06
  • 1
    Your question needs a lot more detail. What will happen with the return value of one function? Is it passed on as argument to the next function in the queue? Or are all results to be gathered in an array with one element corresponding to one return value of one function? *"I am not able to understand how to implement"* is not a question, and if it were, it is too broad. What specifically have you tried and bumped into an issue? – trincot Feb 10 '18 at 19:08
  • No, the return value will not be passed to the next function as an argument. I just need it to assign it to some variable. – Rishab Jain Feb 10 '18 at 19:13
  • https://github.com/jessetane/queue I have tried using this package and it works just fine for me except that I am not able to get the value returned by the function that I have pushed in the queue. – Rishab Jain Feb 10 '18 at 19:15
  • you can use rethinkdb-job-queue. please check https://stackoverflow.com/questions/48724479/job-queue-with-concurrency-control – Chirag Mar 04 '18 at 08:45

0 Answers0