class Riffer::Rig::Runtime::Abort
Constants
- SHIELD
-
Rigβs own callbacks (hooks, tools, stores, the host) run under this, so the signal never cuts one off halfway.
Public Class Methods
() → void
Source
# File lib/riffer/rig/runtime/abort.rb, line 15 def initialize @mutex = Mutex.new @thread = nil end
@rbs return: void
Public Instance Methods
() → void
Source
# File lib/riffer/rig/runtime/abort.rb, line 39 def fire @mutex.synchronize do # Upstream candidate: a cancel token on riffer's run loop. A turn waiting # on the provider is blocked in an HTTP read that runs no rig code, so # only an exception raised into its thread can wake it. @thread&.raise(Signal) # One signal a window, which is all #discard_pending can clear. @thread = nil end end
@rbs return: void
() { () → Riffer::Agent::Response } → Riffer::Agent::Response?
Source
# File lib/riffer/rig/runtime/abort.rb, line 22 def window(&) Thread.handle_interrupt(SHIELD) do arm(Thread.current) begin # Only at a blocking call, so the bookkeeping riffer does between two # callbacks (recording a batch of tool results) is never split. Thread.handle_interrupt(Signal => :on_blocking, &) rescue Signal nil ensure arm(nil) discard_pending end end end
@rbs &: () -> Riffer::Agent::Response @rbs return: Riffer::Agent::Response?