ractor-channel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d49af708a0ef236e77beeab0e6978aadfbb71e614fe0cbac1d55c9758dd559a
4
+ data.tar.gz: 99f95cb711625df925e09732d38c9bf2cd459785f940eb886e1847b4cc539eeb
5
+ SHA512:
6
+ metadata.gz: 46b75bf5181356fa29173e7808e5c1a50a3df2b4f7d557d3b76862ab6e89bdebbcaf82afc2fddbb18d4a0b6fff25fc50941e5fb0757026d988f9dca9b61954f4
7
+ data.tar.gz: ae6b40c589360e2cedf4123e953f8481d635946d94421d44be6fa5a338e9362c6a544bf613a999b73cec86c4c21b2d70974c23b9fac1ca21a277772fbdb63a97
@@ -0,0 +1,49 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ tests:
11
+ name: >-
12
+ Specs | ${{ matrix.ruby }}
13
+ runs-on: ${{ matrix.os }}-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ os: [ ubuntu ]
18
+ ruby: [ head ]
19
+ steps:
20
+ - name: checkout
21
+ uses: actions/checkout@v2
22
+ - name: set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+ - name: install dependencies
27
+ run: bundle install --jobs 3 --retry 3
28
+ - name: spec
29
+ run: bundle exec rake
30
+ internal_investigation:
31
+ name: >-
32
+ Coding Style
33
+ runs-on: ${{ matrix.os }}-latest
34
+ strategy:
35
+ fail-fast: false
36
+ matrix:
37
+ os: [ ubuntu ]
38
+ ruby: [ head ]
39
+ steps:
40
+ - name: checkout
41
+ uses: actions/checkout@v2
42
+ - name: set up Ruby
43
+ uses: ruby/setup-ruby@v1
44
+ with:
45
+ ruby-version: ${{ matrix.ruby }}
46
+ - name: install dependencies
47
+ run: bundle install --jobs 3 --retry 3
48
+ - name: internal investigation
49
+ run: bundle exec rubocop
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
14
+ .rubocop-https*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/ractor-tools/rubocop-ractor-tools/master/.rubocop.yml
@@ -0,0 +1 @@
1
+ 3
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at github@marc-andre.ca. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in ractor-channel.gemspec
6
+ gemspec
7
+
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'rubocop'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Marc-Andre Lafortune
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,59 @@
1
+ # Ractor::Channel
2
+
3
+ Adds a `channel:` option to `Ractor#send` and `Ractor.receive`
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ractor-channel'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require 'ractor-channel'
17
+
18
+ using Ractor::Channel
19
+
20
+ r = Ractor.new do
21
+ puts Ractor.receive channel: :info # Specific channel
22
+ puts Ractor.receive # Default channel (nil)
23
+ puts Ractor.receive channel: :* # Any channel
24
+ end
25
+
26
+ r.send :read_last, channel: :other
27
+ r.send :read_second
28
+ r.send :read_first, channel: :info
29
+ r.take
30
+
31
+ # Prints "read_first, read_second, read_last"
32
+ ```
33
+
34
+ Using refinements is recommended, but it can alternatively be setup globally:
35
+
36
+ ```ruby
37
+ require 'ractor-channel'
38
+
39
+ Ractor.prepend Ractor::Channel
40
+ ```
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ 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).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcandre/ractor-channel. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/marcandre/ractor-channel/blob/master/CODE_OF_CONDUCT.md).
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the Ractor::Channel project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcandre/ractor-channel/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ractor/channel'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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/local_variable'
4
+ require_relative 'channel/version'
5
+
6
+ class Ractor
7
+ module Channel
8
+ SAVED_BY_CHANNEL = Ractor::LocalVariable.new(delegate: true) do
9
+ mutex = ::Mutex.new
10
+ Hash.new do |h, channel|
11
+ mutex.synchronize do
12
+ h.fetch(channel) { h[channel] = ::Queue.new }
13
+ end
14
+ end
15
+ end
16
+
17
+ def send(value, channel: nil, **options)
18
+ super([channel, value].freeze, **options)
19
+ end
20
+
21
+ module ClassMethods
22
+ def receive(channel: nil) # rubocop:disable Metrics/MethodLength (https://bugs.ruby-lang.org/issues/17374)
23
+ if channel == :*
24
+ SAVED_BY_CHANNEL.each do |_channel, queue|
25
+ return queue.pop(true)
26
+ rescue ThreadError
27
+ # try next channel
28
+ end
29
+ super() # # FIXME: Not thread-safe
30
+ else
31
+ loop do
32
+ return SAVED_BY_CHANNEL[channel].pop(true)
33
+ rescue ThreadError
34
+ dest_channel, message = super()
35
+ SAVED_BY_CHANNEL[dest_channel] << message
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.prepended(base)
42
+ base.singleton_class.prepend(ClassMethods)
43
+ end
44
+
45
+ refine Ractor do
46
+ prepend Ractor::Channel
47
+ end
48
+
49
+ refine Ractor.singleton_class do
50
+ prepend Ractor::Channel::ClassMethods
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Ractor
4
+ module Channel
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/ractor/channel/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ractor-channel'
7
+ spec.version = Ractor::Channel::VERSION
8
+ spec.authors = ['Marc-Andre Lafortune']
9
+ spec.email = ['github@marc-andre.ca']
10
+
11
+ spec.summary = 'Add channels to Ractor.'
12
+ spec.description = 'Add channels to Ractor.'
13
+ spec.homepage = 'https://github.com/marcandre/ractor-channel'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.add_dependency 'ractor-local_variable'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
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
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ractor-channel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marc-Andre Lafortune
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ractor-local_variable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ description: Add channels to Ractor.
28
+ email:
29
+ - github@marc-andre.ca
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/ractor-channel.yml"
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - ".ruby-version"
39
+ - ".travis.yml"
40
+ - CODE_OF_CONDUCT.md
41
+ - Gemfile
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/setup
47
+ - lib/ractor/channel.rb
48
+ - lib/ractor/channel/version.rb
49
+ - ractor-channel.gemspec
50
+ homepage: https://github.com/marcandre/ractor-channel
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ homepage_uri: https://github.com/marcandre/ractor-channel
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.2.0.rc.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Add channels to Ractor.
74
+ test_files: []