Skip to content
Get started

Wait for instance to reach a target state

client.Instances.Wait(ctx, id, query) (*WaitForStateResponse, error)
get/instances/{id}/wait

Blocks until the instance reaches the specified target state, the timeout expires, or the instance enters a terminal/error state. Useful for avoiding client-side polling when waiting for state transitions (e.g. waiting for an instance to become Running).

ParametersExpand Collapse
id string
query InstanceWaitParams
State param.Field[InstanceWaitParamsState]

Target state to wait for

const InstanceWaitParamsStateCreated InstanceWaitParamsState = "Created"
const InstanceWaitParamsStateInitializing InstanceWaitParamsState = "Initializing"
const InstanceWaitParamsStateRunning InstanceWaitParamsState = "Running"
const InstanceWaitParamsStatePaused InstanceWaitParamsState = "Paused"
const InstanceWaitParamsStateShutdown InstanceWaitParamsState = "Shutdown"
const InstanceWaitParamsStateStopped InstanceWaitParamsState = "Stopped"
const InstanceWaitParamsStateStandby InstanceWaitParamsState = "Standby"
const InstanceWaitParamsStateUnknown InstanceWaitParamsState = "Unknown"
Timeout param.Field[string]optional

Maximum duration to wait (Go duration format, e.g. "30s", "2m"). Capped at 5 minutes. Defaults to 60 seconds.

ReturnsExpand Collapse
type WaitForStateResponse struct{…}
State WaitForStateResponseState

Current instance state when the wait completed

Accepts one of the following:
const WaitForStateResponseStateCreated WaitForStateResponseState = "Created"
const WaitForStateResponseStateInitializing WaitForStateResponseState = "Initializing"
const WaitForStateResponseStateRunning WaitForStateResponseState = "Running"
const WaitForStateResponseStatePaused WaitForStateResponseState = "Paused"
const WaitForStateResponseStateShutdown WaitForStateResponseState = "Shutdown"
const WaitForStateResponseStateStopped WaitForStateResponseState = "Stopped"
const WaitForStateResponseStateStandby WaitForStateResponseState = "Standby"
const WaitForStateResponseStateUnknown WaitForStateResponseState = "Unknown"
TimedOut bool

Whether the timeout expired before the target state was reached

StateError stringoptional

Error message when derived state is Unknown

Wait for instance to reach a target state
package main

import (
  "context"
  "fmt"

  "github.com/kernel/hypeman-go"
  "github.com/kernel/hypeman-go/option"
)

func main() {
  client := hypeman.NewClient(
    option.WithAPIKey("My API Key"),
  )
  waitForStateResponse, err := client.Instances.Wait(
    context.TODO(),
    "id",
    hypeman.InstanceWaitParams{
      State: hypeman.InstanceWaitParamsStateCreated,
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", waitForStateResponse.State)
}
{
  "state": "Created",
  "timed_out": true,
  "state_error": "state_error"
}
Returns Examples
{
  "state": "Created",
  "timed_out": true,
  "state_error": "state_error"
}