ractor-tmvar 0.1.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 452e6a7f21ca12c8163f6b2c9a90169705b92e28bcbb0e5a2a41fb66c0d6b258
4
+ data.tar.gz: 33e776a975119f6d61593870cb317bdd8a8b45693178613098ef359d4fefb2f5
5
+ SHA512:
6
+ metadata.gz: 57c2cdd4d7918a3869120ca8565a67de62accad9f1e46fa5e4dced91d4f36eb584122ec5fe0923fd263f2b39b64116509ece1a85b41cf82df9b8182506ba618e
7
+ data.tar.gz: 26cfe85a897f01216cb68a783e259d03a7563905cf70eacde9a157795db0555cf7cb78417124196fddad46a8f574b7cc490a471593d512d778d0dce6889da326
@@ -0,0 +1,20 @@
1
+ name: Development
2
+ on: [push,pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu]
9
+ ruby: [head, debug]
10
+
11
+ runs-on: ${{ matrix.os }}-latest
12
+ continue-on-error: ${{ matrix.ruby == 'head' || matrix.ruby == 'debug' }}
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+
19
+ - run: bundle install
20
+ - run: bundle exec rake
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ractor-tmvar.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "test-unit", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 0.80"
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ractor-tmvar (0.1.0)
5
+ ractor-tvar (~> 0.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.1)
11
+ parallel (1.20.1)
12
+ parser (2.7.2.0)
13
+ ast (~> 2.4.1)
14
+ power_assert (1.2.0)
15
+ ractor-tvar (0.3.0)
16
+ rainbow (3.0.0)
17
+ rake (13.0.1)
18
+ regexp_parser (2.0.0)
19
+ rexml (3.2.4)
20
+ rubocop (0.93.1)
21
+ parallel (~> 1.10)
22
+ parser (>= 2.7.1.5)
23
+ rainbow (>= 2.2.2, < 4.0)
24
+ regexp_parser (>= 1.8)
25
+ rexml
26
+ rubocop-ast (>= 0.6.0)
27
+ ruby-progressbar (~> 1.7)
28
+ unicode-display_width (>= 1.4.0, < 2.0)
29
+ rubocop-ast (1.2.0)
30
+ parser (>= 2.7.1.5)
31
+ ruby-progressbar (1.10.1)
32
+ test-unit (3.3.7)
33
+ power_assert
34
+ unicode-display_width (1.7.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ ractor-tmvar!
41
+ rake (~> 13.0)
42
+ rubocop (~> 0.80)
43
+ test-unit (~> 3.0)
44
+
45
+ BUNDLED WITH
46
+ 2.2.0.rc.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 yoshitsugu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # Ractor::TMVar
2
+
3
+ TMVar for Ractor inspired by [Haskell's TMVar](https://hackage.haskell.org/package/stm-2.5.0.0/docs/Control-Concurrent-STM-TMVar.html) based on [Ractor::TVar](https://github.com/ko1/ractor-tvar).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ractor-tmvar'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ractor-tmvar
20
+
21
+ ## Usage
22
+
23
+ Please see [Ractor::TVar](https://github.com/ko1/ractor-tvar) before using this.
24
+ Now we have only `value` and `value=` operations.
25
+
26
+ ```ruby
27
+ require 'ractor-tmvar'
28
+
29
+ tv1 = Ractor::TMVar.new(0)
30
+ tv2 = Ractor::TMVar.new(0)
31
+ rs = 100.times.map do
32
+ Ractor.new tv1, tv2 do |v1, v2|
33
+ value1 = nil
34
+ value2 = nil
35
+ Ractor.atomically do
36
+ # take value similar to takeTMVar in Haskell
37
+ value1 = v1.value
38
+ value2 = v2.value
39
+ end
40
+ Ractor.atomically do
41
+ # set value similar to putTMVar in Haskell
42
+ v2.value = value2 + 2
43
+ v1.value = value1 + 1
44
+ end
45
+ end
46
+ end
47
+ rs.each(&:take)
48
+ assert_equal 100, tv1.value
49
+ assert_equal 200, tv2.value
50
+ ```
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshitsugu/ractor-tmvar.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ #!/usr/bin/env ruby
4
+
5
+ require "bundler/setup"
6
+ require "ractor/tmvar"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ractor/tvar"
4
+
5
+ class Ractor
6
+ # TMVar for Ractor inspired by Haskell's TMVar based on Ractor::TVar.
7
+ class TMVar
8
+ #
9
+ # Represents "blank" value for TMVar
10
+ #
11
+ BLANK = :RACTOR_TMVAR_BLANK
12
+
13
+ #
14
+ # TMVar.new(value) to initialize TMVar
15
+ #
16
+ # @param [Object] tvar neet to be shareable
17
+ #
18
+ # @return [TMVar]
19
+ #
20
+ def initialize(tvar = nil)
21
+ @tvar = Ractor::TVar.new(tvar)
22
+ end
23
+
24
+ #
25
+ # Get TVar's value and leave the value to "blank".
26
+ # If the value is already "blank", it will retry the transaction.
27
+ #
28
+ # @return [Object] value of internal TVar.
29
+ #
30
+ def value
31
+ v = @tvar.value
32
+ raise Ractor::RetryTransaction if v == BLANK
33
+
34
+ # NOTE: TVar cannot be set without `Ractor.atomically`.
35
+ Ractor.atomically do
36
+ @tvar.value = BLANK
37
+ end
38
+ v
39
+ end
40
+
41
+ #
42
+ # Put value to TVar's value.
43
+ # If the value is not "blank", it will retry the transaction.
44
+ #
45
+ # @param [Object] new_value neet to be shareable
46
+ #
47
+ def value=(new_value)
48
+ raise Ractor::RetryTransaction if @tvar.value != BLANK
49
+
50
+ @tvar.value = new_value
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Ractor
4
+ class TMVar
5
+ VERSION = "0.1.2"
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ractor/tmvar/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ractor-tmvar"
7
+ spec.version = Ractor::TMVar::VERSION
8
+ spec.authors = ["yoshitsugu"]
9
+ spec.email = ["yoshitsugu@users.noreply.github.com"]
10
+
11
+ spec.summary = "Ractor::TMVar"
12
+ spec.description = "Introduce Ractor::TMVar based on Ractor::TVar"
13
+ spec.homepage = "https://github.com/yoshitsugu/ractor-tmvar"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.2")
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = spec.homepage
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency "ractor-tvar", "~> 0.3.0"
33
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ractor-tmvar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - yoshitsugu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ractor-tvar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ description: Introduce Ractor::TMVar based on Ractor::TVar
28
+ email:
29
+ - yoshitsugu@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/main.yml"
35
+ - ".gitignore"
36
+ - ".rubocop.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/ractor/tmvar.rb
45
+ - lib/ractor/tmvar/version.rb
46
+ - ractor-tmvar.gemspec
47
+ homepage: https://github.com/yoshitsugu/ractor-tmvar
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/yoshitsugu/ractor-tmvar
52
+ source_code_uri: https://github.com/yoshitsugu/ractor-tmvar
53
+ changelog_uri: https://github.com/yoshitsugu/ractor-tmvar
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.7.2
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.2.0.rc.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Ractor::TMVar
73
+ test_files: []