namo.rb 0.32.9 → 0.32.10

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: 1ac4c2ed4449845cc475c09c946ae8af32b1ba977bed2353b1a665d597e108e5
4
- data.tar.gz: 6e221c9bbe2cfc562018b57fdbd4b8476868c203385bc3ca1d9dbd19c209dda0
3
+ metadata.gz: 102a39ba577957cdb56d734c56e89093be6564c1e0e5a4f51ec1fcdda9d281a3
4
+ data.tar.gz: bc01e5043bd56cc9e178074332b36524b400cef4ad4f3cb35f2e6b88a50a68d2
5
5
  SHA512:
6
- metadata.gz: f9331f7db05e3764548010efdc808f09b12f183a31ff6c6655f0a90644653128ce3696062b090921f47f941441a0a1d92f676a2b54a8c1e3c53aabbbeecafbcc
7
- data.tar.gz: 511c00d86f20a981154be910d1345d309c6fdd45636e33a7bceeee626803a69f46553fa969495210f264d1f7921e6f29d3c800f1cb8f5b23592cc02e8e996371
6
+ metadata.gz: 3e2c6203b00c8e4799f45702e1776d51415399b68587e73c43aa539bff007ef054c1a69c0d23abd78f63acfd9433d99811b470ff9dc16583b0359608da889e9c
7
+ data.tar.gz: e10bcedae84d2a301a8f9188a5694f2f44202b6e8b787380fa698251ff8222b612265d741359596f98a823a3a172e20f7ca679119b7fb7783781cc0c6af8e25e
data/CHANGELOG CHANGED
@@ -1,5 +1,14 @@
1
1
  # namo/CHANGELOG
2
2
 
3
+ ## 20261103
4
+
5
+ 0.32.10: ~ Namo#materialising: A frozen Namo can be read again, and two threads reading one Namo no longer share a scope.
6
+
7
+ 1. ~ Namo#materialising, #values_for: + #materialised_scopes, - @materialised. An access's scope is held per fiber, keyed by the Namo, rather than on the Namo itself. Since 0.29.0, every read wrote to the Namo, so values, coordinates, and to_a raised FrozenError on a frozen Namo, and two threads reading one Namo shared a scope which either could clear while the other was using it.
8
+ 2. ~ test/namo_test.rb: Reading a frozen Namo through a two-arity formula is tested, as is an access keeping its scope when another thread's access to the same Namo ends part-way through it.
9
+ 3. ~ ROADMAP.md: The 0.32.10 change is described.
10
+ 4. ~ Namo::VERSION: /0.32.9/0.32.10/
11
+
3
12
  ## 20261102
4
13
 
5
14
  0.32.9: + comparison/setup: Builds the environments the comparison/*_claims scripts run in, at the versions COMPARISON.md names, or with --latest the newest releases.
data/lib/Namo/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Namo::VERSION
3
3
 
4
4
  class Namo
5
- VERSION = '0.32.9'
5
+ VERSION = '0.32.10'
6
6
  end
data/lib/namo.rb CHANGED
@@ -368,18 +368,25 @@ class Namo
368
368
  end
369
369
  end
370
370
 
371
+ # An access's scope is held per fiber, keyed by the Namo, rather than on the Namo
372
+ # itself, so as a frozen Namo can be read and two threads reading one Namo don't
373
+ # share a scope.
371
374
  def materialising
372
- return yield if @materialised
373
- @materialised = {}
375
+ return yield if materialised_scopes.key?(self)
376
+ materialised_scopes[self] = {}
374
377
  begin
375
378
  yield
376
379
  ensure
377
- @materialised = nil
380
+ materialised_scopes.delete(self)
378
381
  end
379
382
  end
380
383
 
384
+ def materialised_scopes
385
+ Thread.current[:namo_materialised_scopes] ||= {}.compare_by_identity
386
+ end
387
+
381
388
  def values_for(dim)
382
- @materialised[dim] ||= (
389
+ materialised_scopes[self][dim] ||= (
383
390
  if data_dimensions.include?(dim)
384
391
  @data.map{|row_data| row_data[dim]}
385
392
  else
data/test/namo_test.rb CHANGED
@@ -325,6 +325,30 @@ describe Namo do
325
325
  _(namo.values(:agg, :x)).must_equal(agg: [2, 2, 2], x: [1, 2, 3])
326
326
  _(calls).must_equal 3
327
327
  end
328
+
329
+ it "reads a frozen Namo, the scope being held off the receiver" do
330
+ namo = Namo.new([{x: 1}, {x: 2}])
331
+ namo[:double] = proc{|row| row[:x] * 2}
332
+ namo[:total] = proc{|row, namo| namo.values(:double).sum}
333
+ namo.freeze
334
+ _(namo.values(:total)).must_equal [6, 6]
335
+ _(namo.coordinates(:double)).must_equal [2, 4]
336
+ _(namo.to_a).must_equal [{x: 1, double: 2, total: 6}, {x: 2, double: 4, total: 6}]
337
+ end
338
+
339
+ it "gives each thread reading one Namo a scope of its own" do
340
+ namo = Namo.new([{n: 1}])
341
+ entered, released = Queue.new, Queue.new
342
+ holder = nil
343
+ namo[:held] = proc{|row| entered << true; released.pop; row[:n]}
344
+ # :reader's formula lets the holding thread's access finish mid-way through this
345
+ # one, which must leave this access's scope standing for the :n that follows.
346
+ namo[:reader] = proc{|row| released << true; holder.join; row[:n]}
347
+ holder = Thread.new{namo.values(:held)}
348
+ entered.pop
349
+ _(namo.values(:reader, :n)).must_equal(reader: [1], n: [1])
350
+ _(holder.value).must_equal [1]
351
+ end
328
352
  end
329
353
 
330
354
  describe "#to_h" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namo.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.9
4
+ version: 0.32.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran