gleam/otp/supervision

Types

A description a how to start a new child process under an OTP supervisor.

pub type ChildSpecification(data) {
  ChildSpecification(
    start: fn() -> Result(actor.Started(data), actor.StartError),
    restart: Restart,
    significant: Bool,
    child_type: ChildType,
  )
}

Constructors

  • ChildSpecification(
      start: fn() -> Result(actor.Started(data), actor.StartError),
      restart: Restart,
      significant: Bool,
      child_type: ChildType,
    )

    Arguments

    start

    A function to call to start the child process.

    restart

    When the child is to be restarted. See the Restart documentation for more.

    You most likely want the Permanent variant.

    significant

    This defines if a child is considered significant for automatic self-shutdown of the supervisor.

    You most likely do not want to consider any children significant.

    This will be ignored if the supervisor auto shutdown is set to Never, which is the default.

    child_type

    Whether the child is a supervisor or not.

pub type ChildType {
  Worker(shutdown_ms: Int)
  Supervisor
}

Constructors

  • Worker(shutdown_ms: Int)

    A worker child has to shut-down within a given amount of time.

    Arguments

    shutdown_ms

    The number of milliseconds the child is given to shut down. The supervisor tells the child process to terminate by calling exit(Child,shutdown) and then wait for an exit signal with reason shutdown back from the child process. If no exit signal is received within the specified number of milliseconds, the child process is unconditionally terminated using exit(Child,kill).

  • Supervisor

Restart defines when a terminated child process must be restarted.

pub type Restart {
  Permanent
  Transient
  Temporary
}

Constructors

  • Permanent

    A permanent child process is always restarted.

  • Transient

    A transient child process is restarted only if it terminates abnormally, that is, with another exit reason than normal, shutdown, or {shutdown,Term}.

  • Temporary

    A temporary child process is never restarted (even when the supervisor’s restart strategy is RestForOne or OneForAll and a sibling’s death causes the temporary process to be terminated).

Values

pub fn map_data(
  child: ChildSpecification(a),
  transform: fn(a) -> b,
) -> ChildSpecification(b)

Transform the data of the started child process.

pub fn restart(
  child: ChildSpecification(data),
  restart: Restart,
) -> ChildSpecification(data)

When the child is to be restarted. See the Restart documentation for more.

The default value for restart is Permanent.

pub fn significant(
  child: ChildSpecification(data),
  significant: Bool,
) -> ChildSpecification(data)

This defines if a child is considered significant for automatic self-shutdown of the supervisor.

You most likely do not want to consider any children significant.

This will be ignored if the supervisor auto shutdown is set to Never, which is the default.

The default value for significance is False.

pub fn supervisor(
  run start: fn() -> Result(actor.Started(data), actor.StartError),
) -> ChildSpecification(data)

A special child that is a supervisor itself.

pub fn timeout(
  child: ChildSpecification(data),
  ms ms: Int,
) -> ChildSpecification(data)

This defines the amount of milliseconds a child has to shut down before being brutal killed by the supervisor.

If not set the default for a child is 5000ms.

This will be ignored if the child is a supervisor itself.

pub fn worker(
  run start: fn() -> Result(actor.Started(data), actor.StartError),
) -> ChildSpecification(data)

A regular child process.

You should use this unless your process is also a supervisor.

Search Document