Skip to content

Draining the Refresh Broadcast debouncer? #731

Open
@bensheldon

Description

@bensheldon

If I have a short-lived Rails Runner script that calls broadcast_refresh_later_to, it won't get emitted because the script will end before the debouncer's scheduled task hits its delay.

refresh_debouncer_for(*streamables, request_id: request_id).debounce do
Turbo::Streams::BroadcastStreamJob.perform_later stream_name, content: turbo_stream_refresh_tag(request_id: request_id, **opts).to_str # Sidekiq requires job arguments to be valid JSON types, such as String
end

My workaround is to do this at the end of my script, but it's not my favorite:

sleep Turbo::Debouncer::DEFAULT_DELAY + 0.1

It might be nice to keep an Weakmap or something of all of the Turbo::Debounce instances to do something more elegant than sleep (like rescheduling the ScheduledTask to now). I guess I could grab them out of ObjectSpace too. Mostly flagging this as a weird edge case cause I was real confused for 15 minutes till I discovered the cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions