inheritable-thread-vars 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b58d731a5e9622ccc8fdd0197601e0ab8b00b279f16c5411e552814c55d5a9b4
4
- data.tar.gz: 4730063e5de5f19eec5f95bcb40b4a7cf4a3fe057cd00307f8a12ae6902eda38
3
+ metadata.gz: ae7bf95aaa837915cd5c960980747bfb9a627b4a80859649e8ce4e0b246ef91b
4
+ data.tar.gz: c2e348ae8979c9494dfdb2f6fd6e0ed91a7ed551e7705ebfbcc763eef986c482
5
5
  SHA512:
6
- metadata.gz: 701c118a60dd008cb0e829cebb1f7627e8d7d546e7bba3b1c27f1ef87238df74e92905280e37126c3afacc9c51c8c41428b129b8be11eee89844413d03ff1f25
7
- data.tar.gz: 3a5bf27b9cc7f9ab12dd4990cfff8a3377d566ef222c33966724c73c8e759dfc01854a1af50bf1e83b4ebc4fb1cd536bdd71bea970d3179c7be70108a6ea1cf0
6
+ metadata.gz: 2d4d233e66d87ba4f805430c452a67a1685cba66c28c0ddb1221d3ea00f6f8220f3b27c245e6b699674dc8d00c8a69f568e1cf1e7cefa282eabbda6bd043ebf3
7
+ data.tar.gz: 2caa536840b9ae0c9d1a340b002f4ae6746fb4ff7a284254f1027f5918b071de11a22656cb51a91abc413ae778cf740a62c8b400b29f0df9efd5c47768d8253e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.3] - 2025-06-16
2
+
3
+ - Do not .dup parent's thread vars on initialization. Instead, delegate to the parent.
4
+
1
5
  ## [0.0.2] - 2025-04-14
2
6
 
3
7
  - Pass args to Thread.new to its receiving block
@@ -27,19 +27,6 @@ class Thread
27
27
 
28
28
  child.instance_variable_set("@thread_parent", parent)
29
29
 
30
- parent_inheritable_thread_locals = parent.instance_variable_get(:@inheritable_thread_locals)
31
-
32
- if parent_inheritable_thread_locals
33
- if child.instance_variable_defined?(:@inheritable_thread_locals)
34
- # :nocov:
35
- raise "@inheritable_thread_locals has already been declared elsewhere. " \
36
- "Bailing out instead of clobbering it!"
37
- # :nocov:
38
- end
39
-
40
- child.instance_variable_set("@inheritable_thread_locals", parent_inheritable_thread_locals.dup)
41
- end
42
-
43
30
  block.call(*args)
44
31
  end
45
32
  end
@@ -49,10 +36,10 @@ class Thread
49
36
  class << self
50
37
  prepend(InheritableThreadVars::ThreadClassExtensions)
51
38
 
52
- %i[
53
- inheritable_thread_local_var_get
54
- inheritable_thread_local_var_set
55
- with_inheritable_thread_local_var
39
+ [
40
+ :inheritable_thread_local_var_get,
41
+ :inheritable_thread_local_var_set,
42
+ :with_inheritable_thread_local_var
56
43
  ].each do |method_name|
57
44
  if method_defined?(method_name)
58
45
  # :nocov:
@@ -74,10 +61,10 @@ class Thread
74
61
  end
75
62
  end
76
63
 
77
- %i[
78
- inheritable_thread_local_var_get
79
- inheritable_thread_local_var_set
80
- with_inheritable_thread_local_var
64
+ [
65
+ :inheritable_thread_local_var_get,
66
+ :inheritable_thread_local_var_set,
67
+ :with_inheritable_thread_local_var
81
68
  ].each do |method_name|
82
69
  if method_defined?(method_name)
83
70
  # :nocov:
@@ -90,7 +77,13 @@ class Thread
90
77
  # this means that a thread local variable with nil can't have any semantic meaning and should be
91
78
  # treated the same as if #thread_variable? had returned false.
92
79
  def inheritable_thread_local_var_get(var_name)
93
- @inheritable_thread_locals&.[](var_name.to_sym)
80
+ key = var_name.to_sym
81
+
82
+ if @inheritable_thread_locals&.key?(key)
83
+ @inheritable_thread_locals[key]
84
+ else
85
+ @thread_parent&.inheritable_thread_local_var_get(key)
86
+ end
94
87
  end
95
88
 
96
89
  def inheritable_thread_local_var_set(var_name, value)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inheritable-thread-vars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
45
  requirements: []
46
- rubygems_version: 3.6.7
46
+ rubygems_version: 3.6.9
47
47
  specification_version: 4
48
48
  summary: Implements thread variables that default to the parent thread's value
49
49
  test_files: []