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?
registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType) return userConfig.uuid
.then (uuid) -> registerDevice(userConfig.apiKey, userConfig.userId, userConfig.applicationId, userConfig.deviceType)
userConfig.uuid = uuid .tap (uuid) ->
resolve(uuid) userConfig.uuid = uuid
.catch (err) ->
reject(err)
else
uuid = userConfig.uuid
resolve(uuid)
.then (uuid) -> .then (uuid) ->
version = utils.getSupervisorVersion() version = utils.getSupervisorVersion()