private def check()

in management/src/main/scala/org/apache/pekko/management/internal/HealthChecksImpl.scala [204:234]


  private def check(checks: immutable.Seq[HealthCheck]): Future[Either[String, Unit]] = {
    val timeout = pekko.pattern.after(settings.checkTimeout, system.scheduler)(
      Future.failed(new RuntimeException) // will be enriched with which check timed out below
    )

    val spawnedChecks: Seq[Future[Either[String, Unit]]] = checks.map { check =>
      val checkName = check.getClass.getName
      Future.firstCompletedOf(
        Seq(
          timeout.recoverWith {
            case _: Throwable =>
              Future.failed(
                CheckTimeoutException(s"Check [$checkName] timed out after ${settings.checkTimeout}"))
          },
          runCheck(check)
            .map {
              case true  => Right(())
              case false => Left(s"Check [$checkName] not ok")
            }
            .recoverWith {
              case t: Throwable => Future.failed(CheckFailedException(s"Check [$checkName] failed: ${t.getMessage}", t))
            }))
    }

    Future.sequence(spawnedChecks).map { completedChecks =>
      completedChecks.collectFirst { case Left(failure) => failure } match {
        case Some(notOk) => Left(notOk)
        case None        => Right(())
      }
    }
  }