MCPcopy Create free account
hub / github.com/GetStream/stream-cli / WaitForAsyncCompletion

Function WaitForAsyncCompletion

pkg/cmd/chat/utils/async.go:12–40  ·  view source on GitHub ↗
(cmd *cobra.Command, c *stream.Client, taskID string, timeoutSeconds int)

Source from the content-addressed store, hash-verified

10)
11
12func WaitForAsyncCompletion(cmd *cobra.Command, c *stream.Client, taskID string, timeoutSeconds int) error {
13 cmd.Println(fmt.Sprintf("Task id: %s\n", taskID))
14 cmd.Println("Waiting for async task to complete...⏳")
15
16 for i := 0; i < timeoutSeconds; i++ {
17 resp, err := c.GetTask(cmd.Context(), taskID)
18 if err != nil {
19 return err
20 }
21
22 if resp.Status == stream.TaskStatusCompleted {
23 cmd.Println("Async operation completed successfully")
24 return nil
25 }
26 if resp.Status == stream.TaskStatusFailed {
27 return errors.New("async operation failed")
28 }
29
30 if i%5 == 0 {
31 cmd.Print("Still loading... ⏳")
32 }
33
34 time.Sleep(time.Second)
35 }
36
37 cmd.PrintErrf("Async operation timed out after [%d] seconds", timeoutSeconds)
38
39 return nil
40}

Callers 1

NewCmdsFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected