How to create a container

Any

qianmoQqianmoQ· 更新于 2026-10-14· 阅读 3 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Any Wait strategy

The Any multi wait strategy holds a list of wait strategies. The execution of each strategy is asynchronous: all run in their own goroutine. If any one succeeds, the Wait will finish with success (no error) and the remaining running wait strategies will be cancelled. If any one fails, the Wait will finish with an error and the remaining running wait strategies will be cancelled.

Available Options:

  • WithDeadline - the deadline for when all strategies must complete by, default is none.
  • WithStartupTimeoutDefault - the startup timeout default to be used for each Strategy if not defined in seconds, default is 60 seconds.

ForAny Example

// The following are run in parallel. Any that fail will fail the entire
// ForAny. Any that succeed will succeed the ForAny. Either case cancels the
// remaining waiting strategies.
strategy := wait.ForAny(
    wait.ForLog("port: 3306  MySQL Community Server - GPL"),              // Timeout: 120s
    wait.ForExposedPort().WithStartupTimeout(180*time.Second),            // Timeout: 180s
    wait.ForListeningPort("3306/tcp").WithStartupTimeout(10*time.Second), // Timeout: 10s
)

// You can apply a default StartupTimeout for any inner strategy that didn't define it.
strategy = strategy.WithStartupTimeoutDefault(120 * time.Second)

// You can apply an overall deadline for all the strategies to complete within.
strategy = strategy.WithDeadline(360 * time.Second)

// Call WaitUntilReady, or pass the strategy to a function that uses it, to
// start waiting.
_ = strategy.WaitUntilReady(context.Background(), &wait.NopStrategyTarget{})

评论

登录后参与评论

正在加载评论…