fibre 0.9.15 → 0.9.16

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d536a6fb0b1084a7611f3ef4a206e601789c27b3
4
- data.tar.gz: 0ef4ed69f45218b85eba8b2de661d794890710a7
3
+ metadata.gz: 34da33c62386822e000ff1de3e6b122a1dd63e14
4
+ data.tar.gz: dd85505f462fdefa8846678f7ebd2cf821d12a43
5
5
  SHA512:
6
- metadata.gz: fb2b47a27aba9985d048e4c700a2485319db0de87eec49408e1bfd1c4154fc2924f7b80777ca8a2233024ff250e7b6482dbfd7149c85a10c1d7be387fd282c2d
7
- data.tar.gz: 90b60af0e79fd70e46729b2e098dd33c7b621e8183f7ba0e33e178bd832fa7705aa9ebf64b0624801a7bdf77b182e6441a32a2528f1b05f3ffdea7a1eb6dfc2c
6
+ metadata.gz: e6c244d2e343ae57a01c757a6b8e44d47e67bb19e1b25e321bddb8161a2aea8f359a299f72acf32cdd34201665f829475f1f4c8348261502ac422188bcacf84b
7
+ data.tar.gz: c3dd367f4ed5aa44a9bf8dcf33a0e1cf1c33701d08cf87d63784e6ed88e5cb19c1a6edcca609a2c5c07c2f4efd29f19fb4f469366b4ea14a16b07ff4b6434c96
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Inre Storm
1
+ Copyright (c) 2014-2016 Maksim V. <inre.storm@gmail.com>
2
2
 
3
3
  MIT License
4
4
 
@@ -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.7"
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"
@@ -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
- # Fiber.root - root fiber
18
+ # Establish the root fiber
21
19
  attr_accessor :root
22
20
  self.root = Fiber.current
23
21
 
24
- # Pool size can be set before pool initialized
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
- # Initialize with default pool_size
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
- @pool ||= FiberPool.new(pool_size)
33
+ Thread.current[:__fiber_pool] ||= FiberPool.new(pool_size)
32
34
  end
33
35
 
34
36
  def reset
35
- Fibre.root = Fiber.current
36
- Fibre.pool = Fibre::FiberPool.new(pool_size)
37
+ Thread.current[:__fiber_pool] = nil
38
+ pool
37
39
  end
38
40
  end
@@ -1,9 +1,12 @@
1
- require 'fiber'
2
-
1
+ # Extend the Fiber class
2
+ #
3
+ # Outline,
4
+ #
3
5
  # Fiber.sync do |fiber|
4
6
  # fiber.resume response
5
7
  # fiber.leave StandardError, "Something"
6
8
  # end
9
+ require 'fiber'
7
10
 
8
11
  class Fiber
9
12
 
@@ -1,3 +1,11 @@
1
+ # Extend some classes to support synchronous operations
2
+ #
3
+ # Outline,
4
+ #
5
+ # use Fibre::Synchrony
6
+ # [req1, req2].sync
7
+ # { op1: req1, op2: req2 }.sync
8
+
1
9
  module Fibre::Synchrony
2
10
 
3
11
  refine Array do
@@ -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
- # Check-out fiber from pool
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 overflow" if @queue.size > MAX_POOL_QUEUE_SIZE
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
- # Free pool size
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 for all fibers
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
- # Check-in fiber to pool
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
@@ -1,3 +1,3 @@
1
1
  module Fibre
2
- VERSION = "0.9.15"
2
+ VERSION = "0.9.16"
3
3
  end
@@ -4,11 +4,12 @@ describe Fibre do
4
4
  using EventObject
5
5
  using Fibre::Synchrony
6
6
 
7
- before { Fibre.pool = nil }
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
- }.to raise_error
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.15
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: 2015-09-09 00:00:00.000000000 Z
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.7
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.7
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.4.6
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