Skip to content

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.
// 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{})