Class: SplitIoClient::Helpers::ThreadHelper
- Inherits:
-
Object
- Object
- SplitIoClient::Helpers::ThreadHelper
- Defined in:
- lib/splitclient-rb/helpers/thread_helper.rb
Class Method Summary collapse
- .alive?(thread_sym, config) ⇒ Boolean
-
.reap(thread_sym, config, timeout = 1) ⇒ Object
Terminates the thread currently held in
thread_symbefore its handle is replaced. - .stop(thread_sym, config) ⇒ Object
Class Method Details
.alive?(thread_sym, config) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/splitclient-rb/helpers/thread_helper.rb', line 34 def self.alive?(thread_sym, config) thread = config.threads[thread_sym] thread.nil? ? false : thread.alive? end |
.reap(thread_sym, config, timeout = 1) ⇒ Object
Terminates the thread currently held in thread_sym before its handle is
replaced. Thread handles live in a single slot per symbol, so overwriting one
while the thread is still running makes it unreachable and leaks it forever.
24 25 26 27 28 29 30 31 32 |
# File 'lib/splitclient-rb/helpers/thread_helper.rb', line 24 def self.reap(thread_sym, config, timeout = 1) thread = config.threads[thread_sym] return if thread.nil? || thread == Thread.current || !thread.alive? config.logger.warn("#{thread_sym} thread is still alive, terminating it before starting a new one.") Thread.kill(thread) unless thread.join(timeout) rescue StandardError => e config.logger.error(e.inspect) end |
.stop(thread_sym, config) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/splitclient-rb/helpers/thread_helper.rb', line 6 def self.stop(thread_sym, config) thread = config.threads[thread_sym] # Never kill the calling thread: stop_sse is reachable from inside the token # refresh thread, which would otherwise terminate itself mid-flight. return if thread == Thread.current unless thread.nil? config.logger.debug("Stopping #{thread_sym} thread...") if config.debug_enabled Thread.kill(thread) end rescue StandardError => e config.logger.error(e.inspect) end |