ntl-actor 0.2.0 → 0.2.1
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/lib/actor/queue.rb +13 -7
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47b2908a5c8c0845acf09f5f4f7a75e89c913d55
|
4
|
+
data.tar.gz: a90ae411a5f3bc54ee2e169067cf6d3c5c0dcadf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6321566f603c6884202bc129e3435bba0a8f91fd8ae8c06c3a6db16dbf6487b1f43ab82a278a61276200c755cacd0ba23b67a6252ec6d6e80f52422f5aee4a2
|
7
|
+
data.tar.gz: 250ba0a32174e3311debcc64bdf92d63bdddb40df5546657403453879992b315a7493e787400a06a125020f72d7826d0a96ad60cd3d52dd34581a3ab2eb02c48
|
data/lib/actor/queue.rb
CHANGED
@@ -4,6 +4,7 @@ module Actor
|
|
4
4
|
attr_reader :reader_positions
|
5
5
|
attr_reader :list
|
6
6
|
attr_reader :mutex
|
7
|
+
attr_reader :write_queue
|
7
8
|
attr_accessor :tail
|
8
9
|
|
9
10
|
def initialize
|
@@ -11,6 +12,7 @@ module Actor
|
|
11
12
|
@reader_positions = Hash.new 0
|
12
13
|
@list = []
|
13
14
|
@mutex = Mutex.new
|
15
|
+
@write_queue = ::Queue.new
|
14
16
|
@tail = 0
|
15
17
|
end
|
16
18
|
|
@@ -22,7 +24,11 @@ module Actor
|
|
22
24
|
mutex.synchronize do
|
23
25
|
relative_position = position - tail
|
24
26
|
|
25
|
-
|
27
|
+
loop do
|
28
|
+
flush_write_queue
|
29
|
+
|
30
|
+
break if list.count > relative_position
|
31
|
+
|
26
32
|
return nil unless wait
|
27
33
|
|
28
34
|
blocked_threads << Thread.current
|
@@ -66,17 +72,13 @@ module Actor
|
|
66
72
|
end
|
67
73
|
|
68
74
|
def size
|
69
|
-
list.size
|
75
|
+
list.size + write_queue.size
|
70
76
|
end
|
71
77
|
|
72
78
|
def write object
|
73
|
-
# Owning the mutex is not necessary here; the worst that can happen is
|
74
|
-
# that occasionally we write a object when there aren't any readers.
|
75
79
|
return unless readers?
|
76
80
|
|
77
|
-
|
78
|
-
list << object
|
79
|
-
end
|
81
|
+
write_queue << object
|
80
82
|
|
81
83
|
blocked_threads.each &:wakeup
|
82
84
|
end
|
@@ -109,6 +111,10 @@ module Actor
|
|
109
111
|
ref_count
|
110
112
|
end
|
111
113
|
|
114
|
+
def flush_write_queue
|
115
|
+
list << write_queue.deq until write_queue.empty?
|
116
|
+
end
|
117
|
+
|
112
118
|
def up position
|
113
119
|
reader_positions[position] += 1
|
114
120
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntl-actor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Ladd
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Implementation of actor pattern for ruby designed for simplicity and
|
13
|
+
description: Implementation of actor pattern for ruby designed for simplicity and
|
14
|
+
frugality
|
14
15
|
email: nathanladd+github@gmail.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|
@@ -48,7 +49,7 @@ homepage: https://github.com/ntl/actor
|
|
48
49
|
licenses:
|
49
50
|
- MIT
|
50
51
|
metadata: {}
|
51
|
-
post_install_message:
|
52
|
+
post_install_message:
|
52
53
|
rdoc_options: []
|
53
54
|
require_paths:
|
54
55
|
- lib
|
@@ -63,9 +64,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
- !ruby/object:Gem::Version
|
64
65
|
version: '0'
|
65
66
|
requirements: []
|
66
|
-
rubyforge_project:
|
67
|
-
rubygems_version: 2.6.
|
68
|
-
signing_key:
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.6.6
|
69
|
+
signing_key:
|
69
70
|
specification_version: 4
|
70
71
|
summary: Implementation of actor pattern for ruby
|
71
72
|
test_files: []
|