Class: Clacky::CancelFlag

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/cancel_flag.rb

Overview

A one-way, thread-safe cancellation flag shared across a parent agent and the subagents it forks. Fan-out runs each subagent on its own worker thread; when the parent is interrupted the worker threads must learn to stop, but they cannot see the parent's thread-local task epoch. Flipping this flag is the shared signal every subagent polls at its safe checkpoints.

Instance Method Summary collapse

Constructor Details

#initializeCancelFlag

Returns a new instance of CancelFlag.



10
11
12
13
# File 'lib/clacky/cancel_flag.rb', line 10

def initialize
  @mutex = Mutex.new
  @cancelled = false
end

Instance Method Details

#cancel!Object



15
16
17
# File 'lib/clacky/cancel_flag.rb', line 15

def cancel!
  @mutex.synchronize { @cancelled = true }
end

#cancelled?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/clacky/cancel_flag.rb', line 19

def cancelled?
  @mutex.synchronize { @cancelled }
end