Mead.Provider.ServerSentEvents (mead v0.1.1)

Copy Markdown View Source

An incremental parser for text/event-stream bodies.

feed/2 takes the bytes as they arrive, split anywhere, and returns the events that became complete with them. A line ends with \n, \r\n or \r; an event ends with an empty line, so an event whose terminator has not arrived yet stays buffered and is never emitted half-built. Comment lines (starting with :) are dropped, several data: lines of one event are joined with a newline, and an event with no data: line is dropped.

Summary

Types

event()

@type event() :: %{event: String.t() | nil, data: String.t()}

t()

@type t() :: %Mead.Provider.ServerSentEvents{
  buffer: binary(),
  data: [String.t()],
  event: String.t() | nil
}

Functions

feed(parser, chunk)

@spec feed(t(), binary()) :: {[event()], t()}

new()

@spec new() :: t()