fibre 0.9.15 → 0.9.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/fibre.gemspec +1 -1
- data/lib/fibre.rb +11 -9
- data/lib/fibre/core_ext/fiber.rb +5 -2
- data/lib/fibre/core_ext/synchrony.rb +8 -0
- data/lib/fibre/fiber_pool.rb +5 -6
- data/lib/fibre/version.rb +1 -1
- data/spec/fibre_spec.rb +3 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34da33c62386822e000ff1de3e6b122a1dd63e14
|
4
|
+
data.tar.gz: dd85505f462fdefa8846678f7ebd2cf821d12a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6c244d2e343ae57a01c757a6b8e44d47e67bb19e1b25e321bddb8161a2aea8f359a299f72acf32cdd34201665f829475f1f4c8348261502ac422188bcacf84b
|
7
|
+
data.tar.gz: c3dd367f4ed5aa44a9bf8dcf33a0e1cf1c33701d08cf87d63784e6ed88e5cb19c1a6edcca609a2c5c07c2f4efd29f19fb4f469366b4ea14a16b07ff4b6434c96
|
data/LICENSE.txt
CHANGED
data/fibre.gemspec
CHANGED
@@ -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", ">= 1.0
|
24
|
+
spec.add_development_dependency "eventmachine", ">= 1.2.0"
|
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
@@ -3,9 +3,9 @@ require "fibre/version"
|
|
3
3
|
require "fibre/core_ext/fiber"
|
4
4
|
require "fibre/core_ext/synchrony"
|
5
5
|
require "fibre/fiber_error"
|
6
|
+
require "fibre/fiber_pool"
|
6
7
|
|
7
8
|
module Fibre
|
8
|
-
autoload :FiberPool, 'fibre/fiber_pool'
|
9
9
|
autoload :Mock, 'fibre/mock'
|
10
10
|
autoload :Scope, 'fibre/scope'
|
11
11
|
|
@@ -13,26 +13,28 @@ module Fibre
|
|
13
13
|
autoload :FiberPool, 'fibre/rack/fiber_pool'
|
14
14
|
end
|
15
15
|
|
16
|
-
# Configuration module
|
17
|
-
|
18
16
|
extend self
|
19
17
|
|
20
|
-
#
|
18
|
+
# Establish the root fiber
|
21
19
|
attr_accessor :root
|
22
20
|
self.root = Fiber.current
|
23
21
|
|
24
|
-
#
|
22
|
+
# The pool size must be defined before the pool is called
|
25
23
|
attr_accessor :pool_size
|
26
24
|
self.pool_size = 20
|
27
25
|
|
28
|
-
#
|
26
|
+
# Can be changed at any time
|
27
|
+
attr_accessor :max_pool_queue_size
|
28
|
+
self.max_pool_queue_size = 1000
|
29
|
+
|
30
|
+
# Auto-initialize at first call and each thread has own fiber pool
|
29
31
|
attr_writer :pool
|
30
32
|
def pool
|
31
|
-
|
33
|
+
Thread.current[:__fiber_pool] ||= FiberPool.new(pool_size)
|
32
34
|
end
|
33
35
|
|
34
36
|
def reset
|
35
|
-
|
36
|
-
|
37
|
+
Thread.current[:__fiber_pool] = nil
|
38
|
+
pool
|
37
39
|
end
|
38
40
|
end
|
data/lib/fibre/core_ext/fiber.rb
CHANGED
data/lib/fibre/fiber_pool.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
#
|
2
1
|
# Fiber pool
|
3
2
|
#
|
4
3
|
# Example,
|
@@ -21,12 +20,12 @@ module Fibre
|
|
21
20
|
@queue = []
|
22
21
|
end
|
23
22
|
|
24
|
-
#
|
23
|
+
# Borrow fiber from the pool and call the block inside
|
25
24
|
def checkout(&b)
|
26
25
|
spec = { block: b, parent: ::Fiber.current }
|
27
26
|
|
28
27
|
if @pool.empty?
|
29
|
-
raise "fiber queue
|
28
|
+
raise "The fiber queue has been overflowed" if @queue.size > Fibre.max_pool_queue_size
|
30
29
|
@queue.push spec
|
31
30
|
return
|
32
31
|
end
|
@@ -39,7 +38,7 @@ module Fibre
|
|
39
38
|
self
|
40
39
|
end
|
41
40
|
|
42
|
-
#
|
41
|
+
# The size of pool
|
43
42
|
def size
|
44
43
|
@pool.size
|
45
44
|
end
|
@@ -54,7 +53,7 @@ module Fibre
|
|
54
53
|
|
55
54
|
private
|
56
55
|
|
57
|
-
# entrypoint
|
56
|
+
# There is entrypoint running fibers
|
58
57
|
def fiber_entry(spec)
|
59
58
|
loop do
|
60
59
|
raise "wrong spec in fiber block" unless spec.is_a?(Hash)
|
@@ -86,7 +85,7 @@ module Fibre
|
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
89
|
-
#
|
88
|
+
# Return the fiber into the pool
|
90
89
|
def checkin(result=nil)
|
91
90
|
@reserved.delete ::Fiber.current.object_id
|
92
91
|
@pool.unshift ::Fiber.current
|
data/lib/fibre/version.rb
CHANGED
data/spec/fibre_spec.rb
CHANGED
@@ -4,11 +4,12 @@ describe Fibre do
|
|
4
4
|
using EventObject
|
5
5
|
using Fibre::Synchrony
|
6
6
|
|
7
|
-
before { Fibre.
|
7
|
+
before { Fibre.reset }
|
8
8
|
let(:probe) { lambda {} }
|
9
9
|
|
10
10
|
it "should create default pool with default size" do
|
11
11
|
expect(Fibre.pool.size).to be(20)
|
12
|
+
expect(Fibre.max_pool_queue_size).to be(1000)
|
12
13
|
end
|
13
14
|
|
14
15
|
it "should have right root fiber" do
|
@@ -52,7 +53,7 @@ describe Fibre do
|
|
52
53
|
Fibre.pool.checkout do
|
53
54
|
raise_method
|
54
55
|
end
|
55
|
-
|
56
|
+
}.to raise_error(Fibre::FiberError)
|
56
57
|
end
|
57
58
|
|
58
59
|
it "should catch exception" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.16
|
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: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0
|
19
|
+
version: 1.2.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: 1.0
|
26
|
+
version: 1.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: 2.3.0
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.5.1
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Fibre - fiber pool, mock and scoping fibres
|