Files
moby/client/container_wait_example_test.go
Sebastiaan van Stijn 1bb13378c5 client: update examples
- Move "Example" tests separate so that we can use the actual import
- Add "WithUserAgent" in the examples, which should be best practice

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-12 18:53:41 +01:00

30 lines
609 B
Go

package client_test
import (
"context"
"log"
"time"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
)
func ExampleClient_ContainerWait_withTimeout() {
apiClient, err := client.New(
client.FromEnv,
client.WithUserAgent("my-application/1.0.0"),
)
if err != nil {
log.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
wait := apiClient.ContainerWait(ctx, "my_container_id", client.ContainerWaitOptions{
Condition: container.WaitConditionNotRunning,
})
if err := <-wait.Error; err != nil {
log.Fatal(err)
}
}