flammarion 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flammarion/version.rb +1 -1
- data/lib/rubame/rubame.rb +2 -49
- metadata +2 -2
data/lib/flammarion/version.rb
CHANGED
data/lib/rubame/rubame.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'websocket'
|
2
2
|
require 'socket'
|
3
|
-
require 'fiber'
|
4
3
|
|
5
4
|
module Rubame
|
6
5
|
class Server
|
@@ -74,8 +73,8 @@ module Rubame
|
|
74
73
|
client.closed = true
|
75
74
|
end
|
76
75
|
|
77
|
-
def run(
|
78
|
-
readable, writable = IO.select(@reading, @writing, nil
|
76
|
+
def run(&blk)
|
77
|
+
readable, writable = IO.select(@reading, @writing, nil)
|
79
78
|
|
80
79
|
if readable
|
81
80
|
readable.each do |socket|
|
@@ -90,16 +89,6 @@ module Rubame
|
|
90
89
|
blk.call(client) if client and blk
|
91
90
|
end
|
92
91
|
end
|
93
|
-
|
94
|
-
# Check for lazy send items
|
95
|
-
timer_start = Time.now
|
96
|
-
time_passed = 0
|
97
|
-
begin
|
98
|
-
@clients.each do |s, c|
|
99
|
-
c.send_some_lazy(5)
|
100
|
-
end
|
101
|
-
time_passed = Time.now - timer_start
|
102
|
-
end while time_passed < time
|
103
92
|
end
|
104
93
|
|
105
94
|
def stop
|
@@ -116,8 +105,6 @@ module Rubame
|
|
116
105
|
@frame = WebSocket::Frame::Incoming::Server.new(:version => @handshake.version)
|
117
106
|
@opened = false
|
118
107
|
@messaged = []
|
119
|
-
@lazy_queue = []
|
120
|
-
@lazy_current_queue = nil
|
121
108
|
@closed = false
|
122
109
|
@server = server
|
123
110
|
end
|
@@ -136,40 +123,6 @@ module Rubame
|
|
136
123
|
end
|
137
124
|
end
|
138
125
|
|
139
|
-
def lazy_send(data)
|
140
|
-
@lazy_queue.push data
|
141
|
-
end
|
142
|
-
|
143
|
-
def get_lazy_fiber
|
144
|
-
# Create the fiber if needed
|
145
|
-
if @lazy_fiber == nil or !@lazy_fiber.alive?
|
146
|
-
@lazy_fiber = Fiber.new do
|
147
|
-
@lazy_current_queue.each do |data|
|
148
|
-
send(data)
|
149
|
-
Fiber.yield unless @lazy_current_queue[-1] == data
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
return @lazy_fiber
|
155
|
-
end
|
156
|
-
|
157
|
-
def send_some_lazy(count)
|
158
|
-
# To save on cpu cycles, we don't want to be chopping and changing arrays, which could get quite large. Instead,
|
159
|
-
# we iterate over an array which we are sure won't change out from underneath us.
|
160
|
-
unless @lazy_current_queue
|
161
|
-
@lazy_current_queue = @lazy_queue
|
162
|
-
@lazy_queue = []
|
163
|
-
end
|
164
|
-
|
165
|
-
completed = 0
|
166
|
-
begin
|
167
|
-
get_lazy_fiber.resume
|
168
|
-
completed += 1
|
169
|
-
end while (@lazy_queue.count > 0 or @lazy_current_queue.count > 0) and completed < count
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
126
|
def onopen(&blk)
|
174
127
|
if @opened
|
175
128
|
begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flammarion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-01-
|
12
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubame
|