How do I execute a function after the callbacks inside a for loop are completed?

前端 未结 2 520
独厮守ぢ
独厮守ぢ 2021-01-21 03:53

I have a for loop in a search function, with a function that does a callback that does a callback inside the loop, and I want to execute a BUILD() function after the loop, and a

2条回答
  •  礼貌的吻别
    2021-01-21 04:09

    I think you understand this already, but as it is the BUILD() is getting called linearly while the previous callback functions are still running. It's like you've created extra threads. One way to solve the problem would be to make BUILD a callback from the search function with the for loop in it. This would guarantee all functionality is complete before calling it.

    This question might help implement the callback: Create a custom callback in JavaScript

提交回复
热议问题