Cables v0.1.0 Cables.Handler behaviour View Source

Handlers specify how to consume response data.

The handler flow starts with init/3 being called and returning the initial state or an error. In init, additional data can be sent with the request by using Cabels.send_data/2 and Cabels.send_final_data/2.

After getting the new state we wait until we recieve the headers. handle_headers/3 will be called with the status, headers and the state taken from init. A new state should be returned.

After processing the headers, Cables will loop with handle_data/2 until there is no more response data. Each call to handle_data should return a new state for the loop.

After all response data is recieved, handle_finish/1 will be called with the state from handle_data to finish any processing.

Link to this section Summary

Link to this section Callbacks

Link to this callback handle_data(arg0, state) View Source
handle_data(String.t(), state) :: state when state: any()
Link to this callback handle_down(reason, state) View Source
handle_down(reason :: any(), state) :: {:error, any()} when state: any()
Link to this callback handle_finish(state) View Source
handle_finish(state) :: {:ok, any()} when state: any()
Link to this callback handle_headers(integer, list, state) View Source
handle_headers(integer(), [{String.t(), String.t()}], state) :: state
when state: any()
Link to this callback init(gun_pid, stream_ref, init_arg) View Source
init(gun_pid :: pid(), stream_ref :: reference(), init_arg :: term()) ::
  {:ok, state}
when state: any()