Skip to content

Conversation

@jfrery
Copy link
Contributor

@jfrery jfrery commented May 16, 2025

image

var lastStatus: String?

while true {
let statusResponse = try await Network.shared.getStatus(for: serverTask, id: taskID, uid: uid)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do you exit this while true loop ?

self.status = .progress("Analyzing sleep quality…")
case "reserved", "queued":
self.status = .progress("Task is in queue")
case "pending", "failure", "revoked", "unknown", "error":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our design, we added the cancel_task endpoint, which returns the status revoked.
it's a manual cancellation initiated by the user and should not be considered an error.

if statusResponse.status != lastStatus {
lastStatus = statusResponse.status
switch statusResponse.status {
case "started":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just in case, add 'active'

case "completed", "success":
self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date)
self.status = nil
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it exit the 'switch' or the 'while' loop ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i m not familiar with swift, maybe 'return' is more suited

self.resultURL = try await getServerResult(uid: uid, taskID: taskID, for: date)
self.status = nil
break
default: break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should throw an error if we don't know the status of:

default:
throw TaskError.unexpectedStatus(statusResponse.status)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants