fiber_space 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fiber_space/chain.rb +28 -7
- data/lib/fiber_space/container.rb +8 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d83521ec38b797598f2693b0beb903d9332577555552fb0542cb12a77a863942
|
4
|
+
data.tar.gz: 55c4da3f518d60657f6f69ad372d9924b685d441d3ce4e183c6ead26ef6498d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2826512bfa1964e7255f04f060cdbc4433b62eefa35c9ac68df62ed4bb4787ea03a4a7267086c7ea4c088634a47ba4707a3bb0e101775d6d0041ef275dc9ac1
|
7
|
+
data.tar.gz: 488de7ce12a07fa8c7d28e7b6fa84adda5f790b034d224be0ee29eb6e892a7ec21aa07c8f7c0991ca10b222cf2e9269fbfe01830eef2cb825338a656a1a467c8
|
data/lib/fiber_space/chain.rb
CHANGED
@@ -2,10 +2,16 @@ module FiberSpace
|
|
2
2
|
# A FiberChain encapsulates and organizes a SortedSet of Fiber or FiberContainer objects. It facilitates the sequential execution of Fiber and FiberContainer objects.
|
3
3
|
class FiberChain
|
4
4
|
|
5
|
+
# @!attribute [r] closed
|
6
|
+
# @return [Boolean] has the chain closed?
|
7
|
+
attr_accessor :closed
|
8
|
+
|
5
9
|
# Constructs a new FiberChain
|
6
10
|
# @param containers [Array] collection of Fibers or FiberContainers.
|
7
|
-
def initialize(*containers)
|
11
|
+
def initialize(*containers, continuous: false)
|
12
|
+
@continuous_mode = continuous
|
8
13
|
@stack = SortedSet.new
|
14
|
+
@closed = false
|
9
15
|
containers.each { |fiber_container| register(fiber_container) }
|
10
16
|
end
|
11
17
|
|
@@ -13,18 +19,22 @@ module FiberSpace
|
|
13
19
|
def iterate
|
14
20
|
@worker ||= Fiber.new do
|
15
21
|
loop do
|
22
|
+
break if !@continuous_mode && complete?
|
23
|
+
|
16
24
|
if @stack.any?(&:completed?)
|
17
25
|
@stack.delete_if(&:completed?)
|
18
26
|
prepare
|
19
27
|
end
|
28
|
+
|
29
|
+
if @continuous_mode
|
30
|
+
Fiber.yield(@stack.each(&:resume))
|
31
|
+
else
|
32
|
+
Fiber.yield(@stack.first&.resume)
|
33
|
+
end
|
20
34
|
rescue StandardError => e
|
21
35
|
puts 'An error occurred during FiberChain#iterate!'
|
22
36
|
puts e.message
|
23
37
|
puts e.backtrace&.join("\n")
|
24
|
-
ensure
|
25
|
-
break if complete?
|
26
|
-
|
27
|
-
Fiber.yield(@stack.first.resume)
|
28
38
|
end
|
29
39
|
end
|
30
40
|
@worker.resume
|
@@ -32,7 +42,14 @@ module FiberSpace
|
|
32
42
|
|
33
43
|
# Begins executing all items within the FiberChain#stack until all items are complete or the stack is empty.
|
34
44
|
def execute
|
35
|
-
|
45
|
+
if @continuous_mode
|
46
|
+
loop do
|
47
|
+
iterate
|
48
|
+
break if @closed
|
49
|
+
end
|
50
|
+
else
|
51
|
+
iterate until complete?
|
52
|
+
end
|
36
53
|
end
|
37
54
|
|
38
55
|
# Pushes an item to the FiberChain#stack
|
@@ -54,7 +71,11 @@ module FiberSpace
|
|
54
71
|
# Has all elements of the FiberChain#stack completed execution?
|
55
72
|
# @return [Boolean]
|
56
73
|
def complete?
|
57
|
-
|
74
|
+
if @continuous_mode
|
75
|
+
@stack.all?(&:completed?) || @closed
|
76
|
+
else
|
77
|
+
@stack.empty? || @stack.all?(&:completed?) || @closed
|
78
|
+
end
|
58
79
|
end
|
59
80
|
|
60
81
|
private
|
@@ -33,19 +33,15 @@ module FiberSpace
|
|
33
33
|
@cache = opt[:cache] || []
|
34
34
|
@source = opt[:source] || Fiber.new do |cached|
|
35
35
|
loop do
|
36
|
-
if
|
36
|
+
if completed?
|
37
37
|
case @target
|
38
38
|
when FiberContainer then @target.completed? ? break : @target.resume
|
39
39
|
when Fiber then @target.resume if @target.alive?
|
40
40
|
else break
|
41
41
|
end
|
42
|
-
elsif @count == :once || completed?
|
43
|
-
break
|
44
42
|
else
|
45
|
-
unless
|
46
|
-
|
47
|
-
Fiber.yield(yield(cached))
|
48
|
-
end
|
43
|
+
@count -= 1 unless @count == :infinite
|
44
|
+
Fiber.yield(yield(cached))
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
@@ -58,7 +54,11 @@ module FiberSpace
|
|
58
54
|
# Is the fiber completed?
|
59
55
|
# @return [Boolean]
|
60
56
|
def completed?
|
61
|
-
|
57
|
+
if @count == :infinite
|
58
|
+
!@source.alive?
|
59
|
+
else
|
60
|
+
@count == :once || @count.zero? || @count.negative? || !@source.alive?
|
61
|
+
end
|
62
62
|
end
|
63
63
|
|
64
64
|
# Mutual comparison operator
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiber_space
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick W.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: druuid
|
@@ -48,6 +48,7 @@ post_install_message:
|
|
48
48
|
rdoc_options: []
|
49
49
|
require_paths:
|
50
50
|
- lib
|
51
|
+
- lib/fiber_space
|
51
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
53
|
requirements:
|
53
54
|
- - ">="
|