44import shutil
55import sys
66import time
7- from typing import TYPE_CHECKING , Any
7+ from typing import TYPE_CHECKING , Any , Tuple
88
99from binarylane .console .runners .command import CommandRunner
1010
@@ -51,17 +51,14 @@ def _progress(self, progress: str) -> None:
5151 blanks = " " * (shutil .get_terminal_size ().columns - 1 )
5252 print (f"\r { blanks } \r { progress } " , end = "" , file = sys .stderr )
5353
54- def response (self , status_code : int , received : Any ) -> None :
55- # If async is requested, use standard handler
56- if self ._async :
57- super ().response (status_code , received )
58- return
54+ def wait_for_action (self , status_code : int , received : Any ) -> Tuple [int , Any ]:
55+ """While received is an ActionResponse, show progress and wait for the action to complete"""
5956
6057 from binarylane .api .actions .get_v2_actions_action_id import sync_detailed
6158 from binarylane .models .action_response import ActionResponse
6259
6360 # FIXME: Extract _get_action(id: int) -> Tuple[int, Any] method so that derived class can call that instead
64- # Derived class may provide an Action ID directly:
61+ # Caller may provide an Action ID directly:
6562 if isinstance (received , int ):
6663 response = sync_detailed (received , client = self ._client )
6764 status_code , received = response .status_code , response .parsed
@@ -82,5 +79,15 @@ def response(self, status_code: int, received: Any) -> None:
8279 response = sync_detailed (received .action .id , client = self ._client )
8380 status_code , received = response .status_code , response .parsed
8481
82+ return status_code , received
83+
84+ def response (self , status_code : int , received : Any ) -> None :
85+ # If async is requested, use standard handler
86+ if self ._async :
87+ super ().response (status_code , received )
88+ return
89+
90+ status_code , received = self .wait_for_action (status_code , received )
91+
8592 # Action has now completed (or errored), process final response
8693 super ().response (status_code , received )
0 commit comments