Wait until the executed promise resolved to a true value, Execute it every x milliseconds and stop after y milliseconds.
npm install angular-wait-until
angular.module('webApp', ['angular.wait-until'])
angular.module('webApp')
.controller('myController', function ($scope, $q, WaitUntil) {
var myPromise = new WaitUntil();
var later = +Date.now() + 500;
$scope.error = 'no error';
myPromise
.stopAfter(1 * 1000)
.tryEvery(100)
.stopOnFailure(false) //Ignore errors
.execute(() => {
return $q((resolve, reject) => {
if (+Date.now() >= later) {
return resolve(true); //some truthy value
}
reject(false);
})
})
.then((value) => $scope.name = 'Yey')
.catch((err) => $scope.error = err);
});
This repo is based on poll-until-promise. There you can read about additional features and functionality