I have a scenario where I am using the $timeout function to call a second function after the completion of the first function but with a 3-second delay. However, I am facing issues as the duration of the first function varies (sometimes it takes 2 seconds, sometimes 3 seconds, and sometimes even 4 or 5 seconds).
Due to this variation in execution time, my second function is being called before the first one completes.
I am looking for possible ways to prevent this from happening. Is there any method to dynamically set the timeout value?
My goal is to ensure that the second function is only called after the completion of the first one.
Here is a snippet of my code:
$scope.otherTipChecker();
$rootScope.$emit("Loader", { loaded: true });
$timeout(function () {
$rootScope.$emit("OverrideTipDetail", {
OverrideTipDetail: $scope.TipDetail
});
$("#tipEditModal").modal('hide');
$rootScope.$emit("Loader", { loaded: false });
}, 5000);