Remix.run Logo
▲ MomsAVoxell 19 hours ago

All the basics are there (chunked mode), I think you’d only need to do some thing things:

    local SSEHandler = class("SSEHandler", turbo.web.RequestHandler)

    function SSEHandler:get()
        self:set_async(true)
        self:set_header("Content-Type", "text/event-stream")
        self:set_header("Cache-Control", "no-cache")
        self:set_chunked_write()

        -- first event
        self:write("data: hello\n\n")
        self:flush()

        -- later events via IOLoop
        local ioloop = turbo.ioloop.instance()
        local count = 0
        local timer
        timer = ioloop:add_timeout(1000, function()
            count = count + 1
            self:write(string.format("data: tick %d\n\n", count))
            self:flush()
            if count < 10 then
                timer = ioloop:add_timeout(1000, timer)  -- reschedule
            else
               self:finish()
            end
        end)
    end