No release in over 3 years
Implements thread variables that default to the parent thread's value
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

inheritable-thread-vars gem

Thread variables are specific to their threads but perhaps you might find yourself in a situation where you would like to set a thread variable to something that is also accessible to any child threads created from that thread. Well, great news then... this gem lets you do just that!

Installation

Typical stuff: add gem "inheritable-thread-vars" to your Gemfile or .gemspec file. Or even just gem install inheritable-thread-vars if just playing with it directly in scripts.

Usage

require "inheritable-thread-vars"

Thread.inheritable_thread_local_var_set("some_var", "parent_value")
Thread.inheritable_thread_local_var_get("some_var") # "parent_value"

Thread.new do
  Thread.inheritable_thread_local_var_get("some_var") # "parent_value"
  Thread.inheritable_thread_local_var_set("some_var", "child_value")
  Thread.inheritable_thread_local_var_get("some_var") # "child_value"
end

Thread.inheritable_thread_local_var_get("some_var") # "parent_value"

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/foobara/inheritable-thread-vars

License

This project is dual licensed under your choice of the Apache-2.0 license and the MIT license. Please see LICENSE.txt for more info.