fibre 0.9.7 → 0.9.9
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 +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +0 -14
- data/fibre.gemspec +3 -3
- data/lib/fibre.rb +1 -2
- data/lib/fibre/core_ext/fiber.rb +5 -6
- data/lib/fibre/fiber_error.rb +18 -0
- data/lib/fibre/fiber_pool.rb +15 -19
- data/lib/fibre/version.rb +1 -1
- data/spec/fibre_spec.rb +35 -11
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 076cc4e6dae00554040ca8e3063d3469a63e1324
|
4
|
+
data.tar.gz: f741ab822b35765328caf475e4b86e65e1e21c2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf5708e702e36d8e118ed143f719bd20da66a37298055546f970aa3f124a4e7b957cf03bc81725c837fcbf22baaca982064668b589a817bca497a0c461d95eba
|
7
|
+
data.tar.gz: c88451330fecee054e8c7bcb4f1ba803d3fbab4ff43062ec6f5ea0b045b02d34be5e0a076f6eff3dfaedbd49cc231b38087519142156b196f12edf069569a3a0
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -29,18 +29,4 @@ Fibre.pool_size = 10
|
|
29
29
|
Fibre.pool.checkout do
|
30
30
|
puts "runned in fiber"
|
31
31
|
end
|
32
|
-
# some fiber raised exception
|
33
|
-
using EventObject
|
34
|
-
Fibre.pool.on :error do |e|
|
35
|
-
puts e.to_s
|
36
|
-
exit
|
37
|
-
end
|
38
32
|
```
|
39
|
-
|
40
|
-
## Contributing
|
41
|
-
|
42
|
-
1. Fork it ( https://github.com/chelovekov/fibre/fork )
|
43
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
-
5. Create a new Pull Request
|
data/fibre.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'fibre/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "fibre"
|
8
8
|
spec.version = Fibre::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["inre"]
|
10
|
+
spec.email = ["inre.storm@gmail.com"]
|
11
11
|
spec.summary = %q{Fibre - fiber pool, mock and scoping fibres}
|
12
12
|
#spec.description = %q{TODO: Write a longer description. Optional.}
|
13
13
|
spec.homepage = ""
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = '>= 2.1.0'
|
22
22
|
spec.required_rubygems_version = '>= 2.3.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency "eventmachine"
|
24
|
+
spec.add_development_dependency "eventmachine-le"
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.6"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3"
|
data/lib/fibre.rb
CHANGED
@@ -2,6 +2,7 @@ require "event_object"
|
|
2
2
|
require "fibre/version"
|
3
3
|
require "fibre/core_ext/fiber"
|
4
4
|
require "fibre/core_ext/synchrony"
|
5
|
+
require "fibre/fiber_error"
|
5
6
|
|
6
7
|
module Fibre
|
7
8
|
autoload :FiberPool, 'fibre/fiber_pool'
|
@@ -12,8 +13,6 @@ module Fibre
|
|
12
13
|
autoload :FiberPool, 'fibre/rack/fiber_pool'
|
13
14
|
end
|
14
15
|
|
15
|
-
class LeaveError < StandardError; end
|
16
|
-
|
17
16
|
# Configuration module
|
18
17
|
|
19
18
|
extend self
|
data/lib/fibre/core_ext/fiber.rb
CHANGED
@@ -30,24 +30,23 @@ class Fiber
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def sync(*a, &b)
|
33
|
-
Fibre::Scope.scope? ? Fibre::Scope.sync(*a, &b) :
|
33
|
+
Fibre::Scope.scope? ? Fibre::Scope.sync(*a, &b) : wait(*a, &b)
|
34
34
|
end
|
35
35
|
|
36
36
|
# raise exception if we catch exception
|
37
37
|
def yield!
|
38
38
|
Fiber.yield.tap do |y|
|
39
|
-
raise y if y.is_a?(Exception)
|
39
|
+
raise FiberError.new(y) if y.is_a?(Exception)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
def sync_it
|
43
|
+
def wait
|
45
44
|
yield(Fiber.current) if block_given?
|
46
45
|
Fiber.yield!
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
def leave(exception
|
51
|
-
|
49
|
+
def leave(exception, message=nil) # deprecated
|
50
|
+
raise exception.new(message)
|
52
51
|
end
|
53
52
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class FiberError < StandardError
|
2
|
+
attr_accessor :parent
|
3
|
+
|
4
|
+
def initialize parent = $!
|
5
|
+
@parent = parent
|
6
|
+
super(parent && parent.to_s)
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_backtrace backtrace
|
10
|
+
bt = backtrace
|
11
|
+
if parent
|
12
|
+
bt = parent.backtrace
|
13
|
+
bt << "<<< parent fiber: #{parent.class.name}: #{parent}"
|
14
|
+
bt.concat backtrace
|
15
|
+
end
|
16
|
+
super bt
|
17
|
+
end
|
18
|
+
end
|
data/lib/fibre/fiber_pool.rb
CHANGED
@@ -7,17 +7,12 @@
|
|
7
7
|
# pool.checkout do
|
8
8
|
# puts "runned in fiber"
|
9
9
|
# end
|
10
|
-
#
|
11
|
-
# # some fiber raised exception
|
12
|
-
# pool.on :error do |e|
|
13
|
-
# puts e.to_s
|
14
|
-
# end
|
15
10
|
|
16
11
|
module Fibre
|
17
12
|
using EventObject
|
18
13
|
|
19
14
|
class FiberPool
|
20
|
-
events :
|
15
|
+
events :before, :after
|
21
16
|
|
22
17
|
# Initialize fibers pool
|
23
18
|
def initialize(size)
|
@@ -37,8 +32,9 @@ module Fibre
|
|
37
32
|
end
|
38
33
|
|
39
34
|
@pool.shift.tap do |fiber|
|
40
|
-
@reserved[fiber.object_id] =
|
41
|
-
fiber.resume(spec)
|
35
|
+
@reserved[fiber.object_id] = spec
|
36
|
+
err = fiber.resume(spec)
|
37
|
+
raise FiberError.new(err) if err.is_a?(Exception)
|
42
38
|
end
|
43
39
|
|
44
40
|
self
|
@@ -64,19 +60,19 @@ module Fibre
|
|
64
60
|
loop do
|
65
61
|
raise "wrong spec in fiber block" unless spec.is_a?(Hash)
|
66
62
|
|
63
|
+
result = nil
|
67
64
|
begin
|
68
65
|
before!(spec)
|
69
66
|
spec[:block].call# *Fiber.current.args
|
70
67
|
after!(spec)
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
|
69
|
+
# catch ArgumentError, IOError, EOFError, IndexError, LocalJumpError, NameError, NoMethodError
|
70
|
+
# RangeError, FloatDomainError, RegexpError, RuntimeError, SecurityError, SystemCallError
|
71
|
+
# SystemStackError, ThreadError, TypeError, ZeroDivisionError
|
74
72
|
rescue StandardError => e
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
rescue Exception => e
|
79
|
-
raise e
|
73
|
+
result = e
|
74
|
+
# catch NoMemoryError, ScriptError, SignalException, SystemExit, fatal etc
|
75
|
+
#rescue Exception
|
80
76
|
end
|
81
77
|
|
82
78
|
unless @queue.empty?
|
@@ -84,15 +80,15 @@ module Fibre
|
|
84
80
|
next
|
85
81
|
end
|
86
82
|
|
87
|
-
spec = checkin
|
83
|
+
spec = checkin(result)
|
88
84
|
end
|
89
85
|
end
|
90
86
|
|
91
87
|
# Check-in fiber to pool
|
92
|
-
def checkin
|
88
|
+
def checkin(result=nil)
|
93
89
|
@reserved.delete ::Fiber.current.object_id
|
94
90
|
@pool.unshift ::Fiber.current
|
95
|
-
::Fiber.yield
|
91
|
+
::Fiber.yield result
|
96
92
|
end
|
97
93
|
end
|
98
94
|
end
|
data/lib/fibre/version.rb
CHANGED
data/spec/fibre_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Fibre do
|
|
21
21
|
expect(probe).to receive(:call)
|
22
22
|
Fibre.pool.checkout(&probe)
|
23
23
|
end
|
24
|
-
|
24
|
+
=begin
|
25
25
|
it "should rescue error in fiber" do
|
26
26
|
expect(probe).to receive(:call)
|
27
27
|
Fibre.pool.on(:error) do |error|
|
@@ -32,6 +32,7 @@ describe Fibre do
|
|
32
32
|
raise
|
33
33
|
end
|
34
34
|
end
|
35
|
+
=end
|
35
36
|
|
36
37
|
it "should scope" do
|
37
38
|
expect(probe).to receive(:call)
|
@@ -42,14 +43,18 @@ describe Fibre do
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
46
|
+
def raise_method
|
47
|
+
raise "test exception"
|
48
|
+
end
|
49
|
+
|
45
50
|
it "should raise uncatched exceptions" do
|
46
51
|
expect {
|
47
52
|
Fibre.pool.checkout do
|
48
|
-
|
53
|
+
raise_method
|
49
54
|
end
|
50
55
|
}.to raise_error
|
51
56
|
end
|
52
|
-
|
57
|
+
=begin
|
53
58
|
it "should catch exception" do
|
54
59
|
Fibre.pool.on :error do |error|
|
55
60
|
# catch exception here
|
@@ -61,7 +66,7 @@ describe Fibre do
|
|
61
66
|
end
|
62
67
|
}.to_not raise_error
|
63
68
|
end
|
64
|
-
|
69
|
+
=end
|
65
70
|
describe "in fiber specs" do
|
66
71
|
|
67
72
|
around do |examples|
|
@@ -84,6 +89,20 @@ describe Fibre do
|
|
84
89
|
end
|
85
90
|
end
|
86
91
|
|
92
|
+
class FibreTestOperationWithException
|
93
|
+
def initialize(number)
|
94
|
+
@number = number
|
95
|
+
end
|
96
|
+
|
97
|
+
def sync
|
98
|
+
Fiber.sync do |f|
|
99
|
+
Fibre.pool.checkout do
|
100
|
+
raise "test"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
87
106
|
it "should Fiber.sync works well" do
|
88
107
|
result = Fiber.sync do |fiber|
|
89
108
|
EM.next_tick do
|
@@ -93,14 +112,19 @@ describe Fibre do
|
|
93
112
|
expect(result).to be :success
|
94
113
|
end
|
95
114
|
|
96
|
-
it "should
|
115
|
+
it "should raise exception in fiber" do
|
97
116
|
expect {
|
98
|
-
|
99
|
-
|
100
|
-
fiber.leave
|
101
|
-
end
|
117
|
+
Fibre.pool.checkout do
|
118
|
+
raise "test"
|
102
119
|
end
|
103
|
-
}.to raise_error
|
120
|
+
}.to raise_error FiberError
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should sync with exception" do
|
124
|
+
expect {
|
125
|
+
op = FibreTestOperationWithException.new(4)
|
126
|
+
op.sync
|
127
|
+
}.to raise_error FiberError
|
104
128
|
end
|
105
129
|
|
106
130
|
it "should sync array (scoping test)" do
|
@@ -132,7 +156,7 @@ describe Fibre do
|
|
132
156
|
op45: [op4, { op5: op5 }]
|
133
157
|
}
|
134
158
|
}.sync!
|
135
|
-
|
159
|
+
|
136
160
|
expect(res).to include(
|
137
161
|
op3: 5,
|
138
162
|
ops: match_array([3,13]),
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fibre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- inre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: eventmachine
|
14
|
+
name: eventmachine-le
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
version: '0.9'
|
83
83
|
description:
|
84
84
|
email:
|
85
|
-
-
|
85
|
+
- inre.storm@gmail.com
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/fibre.rb
|
97
97
|
- lib/fibre/core_ext/fiber.rb
|
98
98
|
- lib/fibre/core_ext/synchrony.rb
|
99
|
+
- lib/fibre/fiber_error.rb
|
99
100
|
- lib/fibre/fiber_pool.rb
|
100
101
|
- lib/fibre/mock.rb
|
101
102
|
- lib/fibre/rack/fiber_pool.rb
|
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
version: 2.3.0
|
124
125
|
requirements: []
|
125
126
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.4.
|
127
|
+
rubygems_version: 2.4.3
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: Fibre - fiber pool, mock and scoping fibres
|