hare v0.2.2 Hare.Core.Conn.State

This module defines the Conn.State struct that holds the state of the Conn process.

State fields

  • bridge - Keeps AMQP connection related state
  • waiting - Keeps clients waiting for a channel
  • reply - A function to reply to waiting clients with a channel

Waiting clients

When connection is established a channel is opened for each waiting client, and the reply function is called with the client and a channel.

Summary

Functions

Establishes connection

Disconnects the bridge

It checks whether the given reference is the monitoring reference of the current established connection

Returns the Bridge conn

Creates a new Conn.State struct

It attempts to open a new channel

Types

interval()
t()
t() :: %Hare.Core.Conn.State{bridge: Hare.Core.Conn.State.Bridge.t, reply: reply, waiting: Hare.Core.Conn.State.Waiting.t}

Functions

connect(state)
connect(t) :: {:ok, t} | {:retry, interval, t}

Establishes connection.

On success replies to all waiting clients with a channel. On failure returns {:retry, interval, state} expecting the caller to wait for that interval before calling connect/1 again.

disconnect(state)
disconnect(t) :: t

Disconnects the bridge.

down?(state, ref)
down?(t, reference) :: boolean

It checks whether the given reference is the monitoring reference of the current established connection.

given_conn(state)
given_conn(t) :: Hare.Adapter.conn

Returns the Bridge conn.

new(config, reply)

Creates a new Conn.State struct.

open_channel(state, client)
open_channel(t, client) :: t

It attempts to open a new channel.

If the connection is established, it uses the reply function to send the result to the client. {:ok, Hare.Core.Chan.t} on success and {:error, reason} on failure.

If the connection is not established, it adds the client to the waiting list and tries to reopen the channel and reply when the connection is established.