Skip to content

cleaner API, more efficient parsing#4

Open
slact wants to merge 10 commits intowojons:masterfrom
slact:master
Open

cleaner API, more efficient parsing#4
slact wants to merge 10 commits intowojons:masterfrom
slact:master

Conversation

@slact
Copy link
Copy Markdown

@slact slact commented Jan 11, 2018

      local SSE = require "resty.sse"

      local headers = {
        ["X-Some-Header-Field"] = "foobar"
      }
      local sse = SSE.new("http://some-pub-sub-server.com/subscriber", headers) --header table is optional
      --never fails, always returns new sse 'object'

      --explicitly calling :connect() is optional. SSE will connect as needed
      local ok, err = sse:connect()
      if not ok then 
        ngx.say("SSE failed: ", err)
        return
      end

      --message processing loop 
      for evt in sse:events() do
        ngx.say("SSE id:", evt.id or "")
        ngx.say("SSE event-type:", evt.type)
        ngx.say("SSE data:", evt.data)
      end
      
      --why did we exit the message processing loop?
      if sse.error then
        ngx.say("SSE error:", sse.error)
      end

don't forget to tag the merge commit 'v0.2.0' for luarocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant