9898 AsyncDiskSnapshotsResourceWithStreamingResponse ,
9999)
100100from ...lib .polling_async import async_poll_until
101+ from ...lib .cancellation import CancellationToken
101102from ...types .devbox_view import DevboxView
102103from ...types .tunnel_view import TunnelView
103104from ...types .shared_params .mount import Mount
@@ -401,12 +402,14 @@ def await_running(
401402 * ,
402403 # Use polling_config to configure the "long" polling behavior.
403404 polling_config : PollingConfig | None = None ,
405+ cancellation_token : CancellationToken | None = None ,
404406 ) -> DevboxView :
405407 """Wait for a devbox to be in running state.
406408
407409 Args:
408410 id: The ID of the devbox to wait for
409411 config: Optional polling configuration
412+ cancellation_token: Token to cancel the wait operation
410413 extra_headers: Send extra headers
411414 extra_query: Add additional query parameters to the request
412415 extra_body: Add additional JSON properties to the request
@@ -417,6 +420,7 @@ def await_running(
417420
418421 Raises:
419422 PollingTimeout: If polling times out before devbox is running
423+ PollingCancelled: If cancellation_token.cancel() is called
420424 RunloopError: If devbox enters a non-running terminal state
421425 """
422426
@@ -443,7 +447,13 @@ def handle_timeout_error(error: Exception) -> DevboxView:
443447 def is_done_booting (devbox : DevboxView ) -> bool :
444448 return devbox .status not in DEVBOX_BOOTING_STATES
445449
446- devbox = poll_until (wait_for_devbox_status , is_done_booting , polling_config , handle_timeout_error )
450+ devbox = poll_until (
451+ wait_for_devbox_status ,
452+ is_done_booting ,
453+ polling_config ,
454+ handle_timeout_error ,
455+ cancellation_token = cancellation_token ,
456+ )
447457
448458 if devbox .status != "running" :
449459 raise RunloopError (f"Devbox entered non-running terminal state: { devbox .status } " )
@@ -455,18 +465,21 @@ def await_suspended(
455465 id : str ,
456466 * ,
457467 polling_config : PollingConfig | None = None ,
468+ cancellation_token : CancellationToken | None = None ,
458469 ) -> DevboxView :
459470 """Wait for a devbox to reach the suspended state.
460471
461472 Args:
462473 id: The ID of the devbox to wait for.
463474 polling_config: Optional polling configuration.
475+ cancellation_token: Token to cancel the wait operation.
464476
465477 Returns:
466478 The devbox in the suspended state.
467479
468480 Raises:
469481 PollingTimeout: If polling times out before the devbox is suspended.
482+ PollingCancelled: If cancellation_token.cancel() is called.
470483 RunloopError: If the devbox enters a non-suspended terminal state.
471484 """
472485
@@ -487,7 +500,13 @@ def handle_timeout_error(error: Exception) -> DevboxView:
487500 def is_terminal_state (devbox : DevboxView ) -> bool :
488501 return devbox .status in DEVBOX_TERMINAL_STATES
489502
490- devbox = poll_until (wait_for_devbox_status , is_terminal_state , polling_config , handle_timeout_error )
503+ devbox = poll_until (
504+ wait_for_devbox_status ,
505+ is_terminal_state ,
506+ polling_config ,
507+ handle_timeout_error ,
508+ cancellation_token = cancellation_token ,
509+ )
491510
492511 if devbox .status != "suspended" :
493512 raise RunloopError (f"Devbox entered non-suspended terminal state: { devbox .status } " )
@@ -510,6 +529,7 @@ def create_and_await_running(
510529 mounts : Optional [Iterable [Mount ]] | Omit = omit ,
511530 name : Optional [str ] | Omit = omit ,
512531 polling_config : PollingConfig | None = None ,
532+ cancellation_token : CancellationToken | None = None ,
513533 repo_connection_id : Optional [str ] | Omit = omit ,
514534 secrets : Optional [Dict [str , str ]] | Omit = omit ,
515535 snapshot_id : Optional [str ] | Omit = omit ,
@@ -535,6 +555,7 @@ def create_and_await_running(
535555
536556 Raises:
537557 PollingTimeout: If polling times out before devbox is running
558+ PollingCancelled: If cancellation_token.cancel() is called
538559 RunloopError: If devbox enters a non-running terminal state
539560 """
540561 # Pass all create_args to the underlying create method
@@ -565,6 +586,7 @@ def create_and_await_running(
565586 return self .await_running (
566587 devbox .id ,
567588 polling_config = polling_config ,
589+ cancellation_token = cancellation_token ,
568590 )
569591
570592 def list (
@@ -2001,6 +2023,7 @@ async def create_and_await_running(
20012023 mounts : Optional [Iterable [Mount ]] | Omit = omit ,
20022024 name : Optional [str ] | Omit = omit ,
20032025 polling_config : PollingConfig | None = None ,
2026+ cancellation_token : CancellationToken | None = None ,
20042027 repo_connection_id : Optional [str ] | Omit = omit ,
20052028 secrets : Optional [Dict [str , str ]] | Omit = omit ,
20062029 snapshot_id : Optional [str ] | Omit = omit ,
@@ -2020,12 +2043,14 @@ async def create_and_await_running(
20202043 Args:
20212044 See the `create` method for detailed documentation.
20222045 polling_config: Optional polling configuration
2046+ cancellation_token: Token to cancel the wait operation
20232047
20242048 Returns:
20252049 The devbox in running state
20262050
20272051 Raises:
20282052 PollingTimeout: If polling times out before devbox is running
2053+ PollingCancelled: If cancellation_token.cancel() is called
20292054 RunloopError: If devbox enters a non-running terminal state
20302055 """
20312056
@@ -2057,6 +2082,7 @@ async def create_and_await_running(
20572082 return await self .await_running (
20582083 devbox .id ,
20592084 polling_config = polling_config ,
2085+ cancellation_token = cancellation_token ,
20602086 )
20612087
20622088 async def await_running (
@@ -2065,12 +2091,14 @@ async def await_running(
20652091 * ,
20662092 # Use polling_config to configure the "long" polling behavior.
20672093 polling_config : PollingConfig | None = None ,
2094+ cancellation_token : CancellationToken | None = None ,
20682095 ) -> DevboxView :
20692096 """Wait for a devbox to be in running state.
20702097
20712098 Args:
20722099 id: The ID of the devbox to wait for
20732100 config: Optional polling configuration
2101+ cancellation_token: Token to cancel the wait operation
20742102 extra_headers: Send extra headers
20752103 extra_query: Add additional query parameters to the request
20762104 extra_body: Add additional JSON properties to the request
@@ -2081,6 +2109,7 @@ async def await_running(
20812109
20822110 Raises:
20832111 PollingTimeout: If polling times out before devbox is running
2112+ PollingCancelled: If cancellation_token.cancel() is called
20842113 RunloopError: If devbox enters a non-running terminal state
20852114 """
20862115
@@ -2105,7 +2134,12 @@ async def wait_for_devbox_status() -> DevboxView:
21052134 def is_done_booting (devbox : DevboxView ) -> bool :
21062135 return devbox .status not in DEVBOX_BOOTING_STATES
21072136
2108- devbox = await async_poll_until (wait_for_devbox_status , is_done_booting , polling_config )
2137+ devbox = await async_poll_until (
2138+ wait_for_devbox_status ,
2139+ is_done_booting ,
2140+ polling_config ,
2141+ cancellation_token = cancellation_token ,
2142+ )
21092143
21102144 if devbox .status != "running" :
21112145 raise RunloopError (f"Devbox entered non-running terminal state: { devbox .status } " )
@@ -2117,18 +2151,21 @@ async def await_suspended(
21172151 id : str ,
21182152 * ,
21192153 polling_config : PollingConfig | None = None ,
2154+ cancellation_token : CancellationToken | None = None ,
21202155 ) -> DevboxView :
21212156 """Wait for a devbox to reach the suspended state.
21222157
21232158 Args:
21242159 id: The ID of the devbox to wait for.
21252160 polling_config: Optional polling configuration.
2161+ cancellation_token: Token to cancel the wait operation.
21262162
21272163 Returns:
21282164 The devbox in the suspended state.
21292165
21302166 Raises:
21312167 PollingTimeout: If polling times out before the devbox is suspended.
2168+ PollingCancelled: If cancellation_token.cancel() is called.
21322169 RunloopError: If the devbox enters a non-suspended terminal state.
21332170 """
21342171
@@ -2147,7 +2184,12 @@ async def wait_for_devbox_status() -> DevboxView:
21472184 def is_terminal_state (devbox : DevboxView ) -> bool :
21482185 return devbox .status in DEVBOX_TERMINAL_STATES
21492186
2150- devbox = await async_poll_until (wait_for_devbox_status , is_terminal_state , polling_config )
2187+ devbox = await async_poll_until (
2188+ wait_for_devbox_status ,
2189+ is_terminal_state ,
2190+ polling_config ,
2191+ cancellation_token = cancellation_token ,
2192+ )
21512193
21522194 if devbox .status != "suspended" :
21532195 raise RunloopError (f"Devbox entered non-suspended terminal state: { devbox .status } " )
0 commit comments