class AgentIrcStreamer::Batcher
Attributes
Public Class Methods
Source
# File lib/agent_irc_streamer.rb, line 12 def initialize(replier:, idle_sec: PARAGRAPH_IDLE_SEC) @replier = replier @idle_sec = idle_sec @buffer = +"" @streamed = false @last_delta_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) @mutex = Mutex.new @stop_idle = false @idle_thread = Thread.new { idle_watch } end
Public Instance Methods
Source
# File lib/agent_irc_streamer.rb, line 23 def <<(text) delta = text.to_s return if delta.empty? @mutex.synchronize do @buffer << delta @last_delta_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) flush_paragraph_breaks end end
Source
# File lib/agent_irc_streamer.rb, line 34 def finish @mutex.synchronize do flush_paragraph_breaks emit_buffer(force: true) end ensure stop_idle_watch end