use promise.try to start promise chain

This commit is contained in:
Aleksis Brezas 2014-10-03 18:39:50 +00:00 committed by Pablo Carranza Vélez
parent 2d4c22d6eb
commit 4cf6ce657a

View File

@ -37,17 +37,12 @@ module.exports = ->
userConfig = require('/boot/config.json') userConfig = require('/boot/config.json')
userConfig.deviceType ?= 'Raspberry Pi' userConfig.deviceType ?= 'Raspberry Pi'
new Promise (resolve, reject) -> Promise.try ->
if not userConfig.uuid? if userConfig.uuid?
return userConfig.uuid
registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType) registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType)
.then (uuid) -> .tap (uuid) ->
userConfig.uuid = uuid userConfig.uuid = uuid
resolve(uuid)
.catch (err) ->
reject(err)
else
uuid = userConfig.uuid
resolve(uuid)
.then (uuid) -> .then (uuid) ->
version = utils.getSupervisorVersion() version = utils.getSupervisorVersion()