Skip to content

Commit

Permalink
fix(home): ensure $interval polling is destroyed
Browse files Browse the repository at this point in the history
This commit ensures that the $interval polling (GET /system) is
destroyed when the client navigates away from the HomeController.
  • Loading branch information
jniles committed May 23, 2016
1 parent b424475 commit f33efb7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions client/src/partials/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('bhima.controllers')
.controller('HomeController', HomeController);

HomeController.$inject = [
'CurrencyService', 'ExchangeRateService', 'SessionService', 'SystemService', '$interval', '$translate'
'CurrencyService', 'ExchangeRateService', 'SessionService', 'SystemService', '$interval', '$translate', '$scope'
];

/**
Expand All @@ -11,7 +11,7 @@ HomeController.$inject = [
* This controller powers the system dashboard shown by default when the user
* signs in.
*/
function HomeController(Currencies, Rates, Session, System, $interval, $translate) {
function HomeController(Currencies, Rates, Session, System, $interval, $translate, $scope) {
var vm = this;

vm.today = new Date();
Expand Down Expand Up @@ -54,8 +54,15 @@ function HomeController(Currencies, Rates, Session, System, $interval, $translat

// set up an interval to periodically reload the system information data
// (every five seconds)
$interval(loadSystemInformation, 5000, false);
var poll = $interval(loadSystemInformation, 5000, false);

// make sure the polling is cleaned up on the $rootChange and the controller's
// $scope is destroyed
$scope.$on('$destroy', function () {
$interval.cancel(poll);
});

// query system events
System.events()
.then(function (events) {
vm.events = events;
Expand Down
2 changes: 1 addition & 1 deletion server/lib/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function deserialize(data) {
class Topic {

/**
* @cosntructor
* @constructor
*
* @description
* Creates two Redis instances, one for sending and the other for receiving.
Expand Down

0 comments on commit f33efb7

Please sign in to comment.