Module: Synctest::Patches::ThreadSingletonPatch
- Defined in:
- lib/synctest/patches.rb
Instance Method Summary collapse
- #fork(*arguments, **keywords, &block) ⇒ Object
- #kill(thread) ⇒ Object
- #new(*arguments, **keywords, &block) ⇒ Object
- #start(*arguments, **keywords, &block) ⇒ Object
- #stop ⇒ Object
Instance Method Details
#fork(*arguments, **keywords, &block) ⇒ Object
103 104 105 106 107 |
# File 'lib/synctest/patches.rb', line 103 def fork(*arguments, **keywords, &block) return super unless Synctest.current_bubble new(*arguments, **keywords, &block) end |
#kill(thread) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/synctest/patches.rb', line 116 def kill(thread) return super unless thread.is_a?(Thread) owner = thread.thread_variable_get(Synctest::THREAD_BUBBLE_KEY) || Synctest.bubble_for(thread) return super unless owner thread.kill end |
#new(*arguments, **keywords, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/synctest/patches.rb', line 65 def new(*arguments, **keywords, &block) bubble = Synctest.current_bubble reserved = false return super unless bubble && block bubble.reserve_child reserved = true created = false thread = super do |*block_arguments, **block_keywords| Synctest.set_current_bubble(bubble) bubble.attach_child(Thread.current) Thread.current.report_on_exception = false error = nil begin block.call(*block_arguments, **block_keywords) rescue Exception => exception # rubocop:disable Lint/RescueException error = exception raise ensure bubble.child_finished(Thread.current, error) Synctest.set_current_bubble(nil) end end created = true thread.instance_variable_set(Synctest::OBJECT_BUBBLE_IVAR, bubble) bubble.(thread) thread ensure bubble&.cancel_child_reservation if reserved && !created end |
#start(*arguments, **keywords, &block) ⇒ Object
97 98 99 100 101 |
# File 'lib/synctest/patches.rb', line 97 def start(*arguments, **keywords, &block) return super unless Synctest.current_bubble new(*arguments, **keywords, &block) end |
#stop ⇒ Object
109 110 111 112 113 114 |
# File 'lib/synctest/patches.rb', line 109 def stop bubble = Synctest.current_bubble return super unless bubble bubble.stop end |