Use once() to guard multiple callbacks

Mentioned in #95
This commit is contained in:
Nick Farina
2015-09-04 10:05:37 -07:00
parent 03417e249a
commit fe4cd285d0

5
app.js
View File

@@ -8,6 +8,7 @@ var Accessory = require('HAP-NodeJS').Accessory;
var Service = require('HAP-NodeJS').Service; var Service = require('HAP-NodeJS').Service;
var Characteristic = require('HAP-NodeJS').Characteristic; var Characteristic = require('HAP-NodeJS').Characteristic;
var accessoryLoader = require('HAP-NodeJS').AccessoryLoader; var accessoryLoader = require('HAP-NodeJS').AccessoryLoader;
var once = require('HAP-NodeJS/lib/util/once').once;
console.log("Starting HomeBridge server..."); console.log("Starting HomeBridge server...");
@@ -118,7 +119,7 @@ function loadPlatforms() {
function loadPlatformAccessories(platformInstance, log) { function loadPlatformAccessories(platformInstance, log) {
asyncCalls++; asyncCalls++;
platformInstance.accessories(function(foundAccessories){ platformInstance.accessories(once(function(foundAccessories){
asyncCalls--; asyncCalls--;
// loop through accessories adding them to the list and registering them // loop through accessories adding them to the list and registering them
@@ -137,7 +138,7 @@ function loadPlatformAccessories(platformInstance, log) {
// were we the last callback? // were we the last callback?
if (asyncCalls === 0 && !asyncWait) if (asyncCalls === 0 && !asyncWait)
publish(); publish();
}); }));
} }
function createAccessory(accessoryInstance, displayName) { function createAccessory(accessoryInstance, displayName) {