Skip to content

foobara/inheritable-thread-vars

Repository files navigation

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.

About

Implements thread local variables that default to the parent thread's value

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE.txt
MIT
LICENSE-MIT.txt

Stars

Watchers

Forks

Packages

No packages published

Languages