My main function run n tasks. Ideally, when such n tasks are done, a callback function of the main function will be called to terminate the whole process. However, some of those n tasks sometimes don't finished (no callback in each task is called), thus prevent main function from terminating?

Is there any way to make sure each task in those n tasks always finishes (callback is called) in case is callback is not called?