fiber_recycling 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fiber_recycling/recycled_fiber.rb +5 -5
- data/lib/fiber_recycling/root_fiber_backend.rb +4 -4
- data/lib/fiber_recycling.rb +0 -3
- data/spec/duck_types_spec.rb +42 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 746dc55b0a096b0ae4cf0b155fd499ef0fd1ca5e
|
4
|
+
data.tar.gz: 1846000c858ba6daa221bd38dd71249a6403fea3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad2b976c652a19ab8ae5965f321b070fe5d4d47f6f2241532bc07bd84a4de37e22500707673ac7d2c7cb7e4411025f576e3506cacec5e75098a0b2c2ddb6d187
|
7
|
+
data.tar.gz: 7ce95f737843b39d461b028b62b29d961ae7aabe1661c09497ee5464844cb28e836bdcb57aa673ee2fe021fd393f9c8f093d8b6a26df57651ac55f79f861dbcf
|
@@ -2,11 +2,11 @@ module FiberRecycling
|
|
2
2
|
class RecycledFiber
|
3
3
|
|
4
4
|
def self.yield(*args)
|
5
|
-
|
5
|
+
::Fiber.yield(*args)
|
6
6
|
end
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@native_fiber =
|
9
|
+
@native_fiber = ::Fiber.new { execution_loop }
|
10
10
|
@state = :initialized
|
11
11
|
start
|
12
12
|
end
|
@@ -29,12 +29,12 @@ module FiberRecycling
|
|
29
29
|
last_reutrn_value = nil
|
30
30
|
loop do
|
31
31
|
@state = :waiting_for_instruction
|
32
|
-
instruction =
|
32
|
+
instruction = ::Fiber.yield(last_reutrn_value)
|
33
33
|
case instruction
|
34
34
|
when :run
|
35
35
|
@state = :executing_block
|
36
|
-
args =
|
37
|
-
proc =
|
36
|
+
args = ::Fiber.yield
|
37
|
+
proc = ::Fiber.yield
|
38
38
|
last_reutrn_value = proc.call(*args)
|
39
39
|
when :close
|
40
40
|
@state = :closed
|
@@ -6,15 +6,15 @@ module FiberRecycling
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def alive?
|
9
|
-
|
9
|
+
::Fiber.root.alive?
|
10
10
|
end
|
11
11
|
|
12
12
|
def inspect
|
13
|
-
|
13
|
+
::Fiber.root.inspect
|
14
14
|
end
|
15
15
|
|
16
16
|
def resume(*args)
|
17
|
-
|
17
|
+
::Fiber.root.resume(*args)
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_s
|
@@ -22,7 +22,7 @@ module FiberRecycling
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def transfer(*args)
|
25
|
-
|
25
|
+
::Fiber.root.transfer(*args)
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
data/lib/fiber_recycling.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fiber_recycling'
|
2
|
+
|
3
|
+
RSpec.describe FiberRecycling::DuckTypes do
|
4
|
+
|
5
|
+
describe FiberRecycling::Fiber do
|
6
|
+
|
7
|
+
context "when creating a Fiber" do
|
8
|
+
it "should create a FiberRecycling::Fiber" do
|
9
|
+
module A
|
10
|
+
include FiberRecycling::DuckTypes
|
11
|
+
|
12
|
+
def self.a
|
13
|
+
Fiber.new {}
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(A.a).to be_a(FiberRecycling::Fiber)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe FiberRecycling::FiberError do
|
25
|
+
|
26
|
+
context "when FiberError is raised" do
|
27
|
+
it "should raise FiberRecycling::FiberError" do
|
28
|
+
module A
|
29
|
+
include FiberRecycling::DuckTypes
|
30
|
+
|
31
|
+
def self.a
|
32
|
+
fiber = Fiber.new {}
|
33
|
+
fiber.resume
|
34
|
+
expect{ fiber.resume }.to raise_error FiberError
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiber_recycling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Fors
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/fiber_recycling/recycled_fiber.rb
|
44
44
|
- lib/fiber_recycling/recycled_fiber_pool.rb
|
45
45
|
- lib/fiber_recycling/root_fiber_backend.rb
|
46
|
+
- spec/duck_types_spec.rb
|
46
47
|
- spec/fiber_spec.rb
|
47
48
|
- spec/spec_helper.rb
|
48
49
|
homepage: https://github.com/robfors/fiber_recycling
|