Implement a spinner when awaiting for a device. Fix #107

Fixes:

- https://github.com/resin-io/resin-cli/issues/107
This commit is contained in:
Juan Cruz Viotti 2015-08-14 14:35:38 -04:00
parent 30f6a78282
commit 30f24333c0
2 changed files with 12 additions and 3 deletions

View File

@ -157,16 +157,18 @@
],
permission: 'user',
action: function(params, options, done) {
var poll;
var poll, spinner;
if (options.interval == null) {
options.interval = 3000;
}
spinner = new visuals.Spinner("Awaiting device: " + params.uuid);
poll = function() {
return resin.models.device.isOnline(params.uuid).then(function(isOnline) {
if (isOnline) {
spinner.stop();
console.info("Device became online: " + params.uuid);
} else {
console.info("Polling device network status: " + params.uuid);
spinner.start();
return Promise.delay(options.interval).then(poll);
}
});

View File

@ -214,13 +214,20 @@ exports.await =
action: (params, options, done) ->
options.interval ?= 3000
spinner = new visuals.Spinner("Awaiting device: #{params.uuid}")
poll = ->
resin.models.device.isOnline(params.uuid).then (isOnline) ->
if isOnline
spinner.stop()
console.info("Device became online: #{params.uuid}")
return
else
console.info("Polling device network status: #{params.uuid}")
# Spinner implementation is smart enough to
# not start again if it was already started
spinner.start()
return Promise.delay(options.interval).then(poll)
poll().nodeify(done)