diff --git a/R/lucid.R b/R/lucid.R index 787852a..443af24 100644 --- a/R/lucid.R +++ b/R/lucid.R @@ -57,28 +57,30 @@ lucidClient <- function(authInfo) { waitForTaskCompletion = function(taskId, quiet = FALSE) { path <- paste("/tasks/", taskId, sep="") - + + cat("Waiting for task: ", taskId, "\n", sep="") + lastStatus <- NULL while(TRUE) { # check status status <- handleResponse(GET(authInfo, path)) + # display status to the user if it changed + if (!identical(lastStatus, status$description)) { + if (!quiet) + cat(" ", status$status, ": ", status$description, "\n", sep="") + lastStatus <- status$description + } + # are we finished? (note: this codepath is the only way to exit # this function) - if (status$finished) { + else if (status$finished) { if (identical(status$status, "complete")) return (NULL) else stop(status$error, call. = FALSE) } - # display status to the user if it changed - else if (!identical(lastStatus, status$status)) { - if (!quiet) - cat(" ", status$status, "\n", sep="") - lastStatus <- status$status - } - # wait for 1 second before polling again Sys.sleep(1) }