Search results

There are no results.

std.net.http.server.Notifier

Atomic
type pub async Notifier[H: mut + Handle]

A type for notifying a Server that it should shut down.

Instance methods

notify

Show source code
Hide source code
fn pub async mut notify(wait: Bool) {
  match @shutdown := Option.None {
    case Some(p) -> {
      # The Promise must be resolved _before_ the connection is made as to
      # ensure the accept() loop correctly wakes up.
      p.set(nil)

      # Wake up the accept() loop using a dummy connection. This must be done
      # _after_ we resolve the Promise as to ensure the accept() loop observes
      # it being resolved _before_ it performs another accept().
      #
      # Any errors that may occur are ignored because we don't really care for
      # them, as we'll shut down eventually.
      #
      # We don't use shutdown() here because only on Linux does it interrupt
      # an accept(), while on other platforms it simply won't work on a socket
      # that isn't already connected.
      match @address {
        case Ip(v) -> drop(TcpClient.new([v.ip], v.port))
        case Unix(v) -> drop(UnixClient.new(v.address.to_path))
      }
    }
    case _ -> {}
  }

  @pool.shutdown(wait)
}
fn pub async mut notify(wait: Bool)

Notifies the connection pool (and thus the server) that it should shut down.

The wait argument specifies if the server should shut down gracefully (true) or immediately (false).