-
-
Save tristanpendergrass/96a4681fe1876258a7b197989f3489ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContentCtrl { | |
constructor($scope, contentItems) { | |
this.readyIntervals = []; // $interval for each content item that we're checking "ready" status of | |
$scope.$on('$destroy', () => { | |
this.readyIntervals.forEach($interval.cancel.bind($interval)); | |
}); | |
this.contentItems = contentItems; | |
this.contentItems.forEach(this.getReadyStatus.bind(this)); | |
} | |
getReadyStatus(item) { | |
const TIME_TO_WAIT = 10000; | |
const POLLING_INTERVAL = 1000; | |
const interval = $interval(() => { | |
$http.get(url) | |
.then((res) => { | |
if (res.data.status === 'Ready') { | |
$interval.cancel(interval); | |
this.readyIntervals.splice(this.readyIntervals.indexOf(interval)); | |
item.status = 'Ready'; | |
} | |
}) | |
}, POLLING_INTERVAL); | |
this.readyIntervals.push(interval); | |
$timeout(() => { | |
$interval.cancel(interval); | |
this.readyIntervals.splice(this.readyIntervals.indexOf(interval)); | |
}, TIME_TO_WAIT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment