Skip to content

Configurable per-call :heartbeat#16

Merged
ismasan merged 1 commit intomainfrom
per_call_heartbeat
Apr 14, 2026
Merged

Configurable per-call :heartbeat#16
ismasan merged 1 commit intomainfrom
per_call_heartbeat

Conversation

@ismasan
Copy link
Copy Markdown
Collaborator

@ismasan ismasan commented Apr 14, 2026

Per-stream heartbeat override

The #stream method also accepts a heartbeat: keyword that overrides the constructor-level setting for a single call. This is useful when a dispatcher is generally configured with a heartbeat but a particular response doesn't need one (e.g. a one-shot update, or multiple updates that don't keep the connection open for long). The previous value is restored once the call returns.

datastar = Datastar.new(request:, response:) # default heartbeat

# Disable heartbeat for this single response
datastar.stream(heartbeat: false) do |sse|
  sse.patch_elements(html)
  sse.patch_signals(progress: 100)
end

The one-shot helpers (#patch_elements, #remove_elements, #patch_signals, #remove_signals, #execute_script, #redirect) use this internally to avoid spawning a heartbeat thread for a single message.

This change is an optimisation aimed mostly at libraries using this SDK. No-heartbeat streams were possible before but not exposed in the public API.

@ismasan ismasan merged commit 393647c into main Apr 14, 2026
1 check passed
@ismasan ismasan deleted the per_call_heartbeat branch April 14, 2026 16:01
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