httpp/sse

Use this to receive server sent events


fn fetch() {
  let subject = process.new_subject()
  let request = uri.from_string("https://example.com/listen")
    |> request.from_uri()

  let mgr = event_source(request, 1000, subject)

  // receive events like any other message
  let event = process.receive(subject, 1000)
}

Types

pub type SSEEvent {
  Event(
    event_type: option.Option(String),
    event_id: option.Option(String),
    data: String,
  )
  Closed
}

Constructors

pub type SSEManagerMessage {
  Shutdown
}

Constructors

  • Shutdown

Values

pub fn event_source(
  req: request.Request(bytes_tree.BytesTree),
  timeout: Int,
  subject: process.Subject(SSEEvent),
) -> Result(
  #(hackney.ClientRef, process.Subject(SSEManagerMessage)),
  actor.StartError,
)

Send a request to a server-sent events endpoint, and receive events back on a subject you provide. The timeout sets how long the actor will wait for the first response (status code, headers)

Search Document