Top Level Namespace
Defined Under Namespace
Modules: Syntropy
Constant Summary collapse
- TAG_DEBUG_PROC =
->(level, fn, line, col) { { 'data-syntropy-level' => level, 'data-syntropy-fn' => fn, 'data-syntropy-loc' => "vscode://file/#{fn}:#{line}:#{col}" } }
Instance Method Summary collapse
-
#call(req) ⇒ Object
Handles incoming requests to the ‘watch.sse` route.
-
#signal! ⇒ Object
Signals a file change by pushing to all watcher queues.
-
#watchers ⇒ Object
Returns a hash holding references to queues for ongoing ‘watch.sse` requests.
Instance Method Details
#call(req) ⇒ Object
Handles incoming requests to the ‘watch.sse` route. Adds a queue to the list of watchers, and waits for the queue to be signalled. In the absence of file change, a timeout occurs after one minute, and the request is terminated.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/syntropy/applets/builtin/auto_refresh/watch.sse.rb', line 24 def call(req) queue = UM::Queue.new watchers[queue] = true req.send_headers('Content-Type' => 'text/event-stream') req.send_chunk("data: \n\n") @machine.timeout(60, Timeout::Error) do @machine.shift(queue) req.send_chunk("data: refresh\n\n") end req.send_chunk("retry: 0\n\n", done: true) rescue nil rescue Timeout::Error req.send_chunk("retry: 0\n\n", done: true) rescue nil rescue SystemCallError # ignore rescue => e @logger&.error( message: 'Unexpected error encountered while serving auto refresh watcher', error: e ) req.finish rescue nil ensure watchers.delete(queue) end |
#signal! ⇒ Object
Signals a file change by pushing to all watcher queues.
17 18 19 |
# File 'lib/syntropy/applets/builtin/auto_refresh/watch.sse.rb', line 17 def signal! watchers.each_key { @machine.push(it, true) } end |
#watchers ⇒ Object
Returns a hash holding references to queues for ongoing ‘watch.sse` requests.
12 13 14 |
# File 'lib/syntropy/applets/builtin/auto_refresh/watch.sse.rb', line 12 def watchers @watchers ||= {} end |