Class: Tool::ThreadLocal
- Inherits:
-
Delegator
- Object
- Delegator
- Tool::ThreadLocal
- Defined in:
- lib/tool/thread_local.rb
Overview
Have thread local values without them actually being thread global.
Advantages:
-
Values for all threads are garbage collected when ThreadLocal instance is.
-
Values for specific thread are garbage collected when thread is.
-
No hidden global state.
-
Supports other data types besides hashes.
Instance Method Summary collapse
-
#initialize(default = {}) ⇒ ThreadLocal
constructor
A new instance of ThreadLocal.
Constructor Details
#initialize(default = {}) ⇒ ThreadLocal
Returns a new instance of ThreadLocal.
63 64 65 66 |
# File 'lib/tool/thread_local.rb', line 63 def initialize(default = {}) @default = default.dup @map = {} end |