thread_root_fiber 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8026c1166beb1938e08c988cb5ca93c6fca7866d
4
+ data.tar.gz: 961caa6197e42b5ca58a51331baaaad057af8e71
5
+ SHA512:
6
+ metadata.gz: bf44b56601ebf5ad295b93d46d74160d9e9a71db3a6d6729e1eb76ac1c4f180ddb5df851dacabfa81d49e0fad893c8181fbad5c16e14c62badef25976208d948
7
+ data.tar.gz: 6748f5813119cc7af42c499d0d33e930d261119d3bb166ad791b55aac86dad81aaba01fa6a0b52bcbce72ded9450f6bec23e8e08ca1c31cc1fd73872863820ac
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Christopher Aue
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.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # ThreadRootFiber
2
+
3
+ Ruby's threads have no access to their root fibers. This little gem adds:
4
+
5
+ - Thread#root_fiber
6
+ - Fiber.root
7
+ - Fiber#root? (also aliased as #root_fiber?)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'thread_root_fiber'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install thread_root_fiber
24
+
25
+ ## Usage
26
+
27
+ `Thread#root_fiber`:
28
+ ```ruby
29
+ Thread.main.root_fiber == Fiber.current # => true
30
+ Thread.main.root_fiber != Thread.new{ Fiber.current }.value # => true
31
+
32
+ thread = Thread.new{ Fiber.current }
33
+ thread.root_fiber == thread.value # => true
34
+ thread.root_fiber != Fiber.current # => true
35
+ ```
36
+
37
+ `Fiber.root`:
38
+ ```ruby
39
+ Fiber.root == Fiber.current # => true
40
+ Fiber.root != Thread.new{ Fiber.current }.value # => true
41
+
42
+ thread = Thread.new{ Fiber.root }
43
+ thread.value == thread.root_fiber # => true
44
+ thread.value != Fiber.root # => true
45
+ ```
46
+
47
+ `Fiber#root?`:
48
+ ```ruby
49
+ Fiber.current.root? # => true
50
+ Fiber.new.root? # => false
51
+
52
+ Thread.new{ Fiber.current.root? }.value # => true
53
+ Thread.new{ Fiber.new.root? }.value # => false
54
+ ```
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
@@ -0,0 +1,6 @@
1
+ require 'fiber'
2
+
3
+ require "thread_root_fiber/version"
4
+ require "thread_root_fiber/thread"
5
+ require "thread_root_fiber/fiber"
6
+
@@ -0,0 +1,12 @@
1
+ class << Fiber
2
+ def root
3
+ Thread.current.root_fiber
4
+ end
5
+ end
6
+
7
+ class Fiber
8
+ def root?
9
+ self == Fiber.root
10
+ end
11
+ alias root_fiber? root?
12
+ end
@@ -0,0 +1,24 @@
1
+ Thread.main.instance_eval{ @root_fiber = Fiber.current }
2
+
3
+ class << Thread
4
+ %i(new start fork).each do |creator|
5
+ alias_method :"__#{creator}_not_setting_root_fiber__", creator
6
+
7
+ eval <<-CODE, nil, __FILE__, __LINE__+1
8
+ def #{creator}(*create_args)
9
+ current_thread = Thread.current
10
+ thread = __#{creator}_not_setting_root_fiber__(*create_args) do |*args|
11
+ Thread.current.instance_eval{ @root_fiber = Fiber.current }
12
+ current_thread.run
13
+ yield *args
14
+ end
15
+ Thread.stop
16
+ thread
17
+ end
18
+ CODE
19
+ end
20
+ end
21
+
22
+ class Thread
23
+ attr_reader :root_fiber
24
+ end
@@ -0,0 +1,3 @@
1
+ module ThreadRootFiber
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thread_root_fiber/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "thread_root_fiber"
8
+ spec.version = ThreadRootFiber::VERSION
9
+ spec.authors = ["Christopher Aue"]
10
+ spec.email = ["mail@christopheraue.net"]
11
+
12
+ spec.summary = %q{Adds Thread#root_fiber, Fiber.root and Fiber#root?}
13
+ spec.description = <<-DESC
14
+ Ruby's threads have no access to their root fibers. This little gem adds:
15
+
16
+ - Thread#root_fiber
17
+ - Fiber.root
18
+ - Fiber#root? (also aliased as #root_fiber?)
19
+ DESC
20
+ spec.homepage = "https://github.com/christopheraue/ruby-thread_root_fiber"
21
+ spec.license = "MIT"
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.12"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thread_root_fiber
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Aue
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: |
56
+ Ruby's threads have no access to their root fibers. This little gem adds:
57
+
58
+ - Thread#root_fiber
59
+ - Fiber.root
60
+ - Fiber#root? (also aliased as #root_fiber?)
61
+ email:
62
+ - mail@christopheraue.net
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".rspec"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - lib/thread_root_fiber.rb
73
+ - lib/thread_root_fiber/fiber.rb
74
+ - lib/thread_root_fiber/thread.rb
75
+ - lib/thread_root_fiber/version.rb
76
+ - thread_root_fiber.gemspec
77
+ homepage: https://github.com/christopheraue/ruby-thread_root_fiber
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Adds Thread#root_fiber, Fiber.root and Fiber#root?
101
+ test_files: []
102
+ has_rdoc: