em-midori 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/lib/midori/core_ext/event_loop.rb +30 -22
- data/lib/midori/version.rb +1 -1
- data/tutorial/README.md +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e4238511fe308c3529be24fbad1cd44b3e436cc
|
4
|
+
data.tar.gz: 9a01e07793ec3b2f72fd2e43f2609aba482798dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 336b392c12a61aafa8538d3d6cad03e7c7c1559432faf4dc879d4dfc16dd0bff2a69822a20e52f79f2fc1fb7198d6bf05111cccf4f57aecf866673ec1f94be4e
|
7
|
+
data.tar.gz: 4714ff8b26be8dcf63fea4f8386cc7c1d0ed200f64058dd9707f945470bc34e024c1b2c2e22ed3c9b0252f4153bfe65324f2ad6b914ebac709da431e32f95768
|
data/LICENSE
CHANGED
@@ -2,21 +2,26 @@
|
|
2
2
|
# EventLoop Module, providing main loop for events
|
3
3
|
module EventLoop
|
4
4
|
class << self
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
# Config EvnetLoop, call by default if any other methods called
|
6
|
+
# @param [NIO::Selector] selector an event selector
|
7
|
+
def config(selector = NIO::Selector.new)
|
8
|
+
# Raw NIO Selector
|
9
|
+
@selector = selector
|
10
|
+
# Array of active timers
|
11
|
+
@timers = []
|
12
|
+
# Hash of io and its callback
|
13
|
+
@ios = Hash.new
|
14
|
+
# IO queue
|
15
|
+
@queue = Hash.new
|
16
|
+
end
|
13
17
|
|
14
18
|
# Add timer in event loop
|
15
19
|
# @param [EventLoop::Timer] timer timer to insert
|
16
20
|
# @return [nil] nil
|
17
21
|
def add_timer(timer)
|
22
|
+
config if @selector.nil?
|
18
23
|
timer.start_time = Time.now.to_f + timer.time
|
19
|
-
|
24
|
+
@timers << timer
|
20
25
|
nil
|
21
26
|
end
|
22
27
|
|
@@ -26,11 +31,11 @@ module EventLoop
|
|
26
31
|
# @yield what to run when io callbacks
|
27
32
|
# @return [nil] nil
|
28
33
|
def register(io, interest=(:rw), &callback)
|
29
|
-
if
|
30
|
-
|
34
|
+
if @queue[io.to_i].nil?
|
35
|
+
@queue[io.to_i] = Array.new
|
31
36
|
register_raw(io, interest, callback)
|
32
37
|
else
|
33
|
-
|
38
|
+
@queue[io.to_i] << [io, interest, callback]
|
34
39
|
end
|
35
40
|
nil
|
36
41
|
end
|
@@ -41,8 +46,9 @@ module EventLoop
|
|
41
46
|
# @param [Proc] callback what to run when io callbacks
|
42
47
|
# @return [nil] nil
|
43
48
|
def register_raw(io, interest=(:rw), callback)
|
44
|
-
|
45
|
-
|
49
|
+
config if @selector.nil?
|
50
|
+
@selector.register(io, interest)
|
51
|
+
@ios[io] = { callback: callback }
|
46
52
|
nil
|
47
53
|
end
|
48
54
|
|
@@ -51,28 +57,30 @@ module EventLoop
|
|
51
57
|
# @return [nil] nil
|
52
58
|
def deregister(io)
|
53
59
|
fd = io.to_i
|
54
|
-
|
55
|
-
|
56
|
-
next_register =
|
57
|
-
next_register.nil? ?
|
60
|
+
@selector.deregister(io)
|
61
|
+
@ios.delete(io)
|
62
|
+
next_register = @queue[fd].shift
|
63
|
+
next_register.nil? ? @queue.delete(fd) : register_raw(*next_register)
|
58
64
|
nil
|
59
65
|
end
|
60
66
|
|
61
67
|
# Run I/O selector once
|
62
68
|
# @return [nil] nil
|
63
69
|
def run_once
|
64
|
-
|
65
|
-
|
70
|
+
config if @selector.nil?
|
71
|
+
@selector.select(0.2) do |monitor| # Timeout for 0.2 secs
|
72
|
+
@ios[monitor.io][:callback].call(monitor)
|
66
73
|
end
|
67
|
-
|
74
|
+
timer_once
|
68
75
|
nil
|
69
76
|
end
|
70
77
|
|
71
78
|
# Run timer once
|
72
79
|
# @return [nil] nil
|
73
80
|
def timer_once
|
81
|
+
config if @selector.nil?
|
74
82
|
now_time = Time.now.to_f
|
75
|
-
|
83
|
+
@timers.delete_if do |timer|
|
76
84
|
if timer.start_time < now_time
|
77
85
|
timer.callback.call
|
78
86
|
true
|
data/lib/midori/version.rb
CHANGED
data/tutorial/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Midori (pronounced /miːdɒliː/) is a **Ruby web framework** for building APIs, web pages and realtime web services. Midori is designed to provide **non-blocking** I/O operations without **callback hells** on web development. The core library is focused on network I/Os, and gives a very easy DSL to pick up and converting existed projects on. On the other hand, midori also officially provides extension libraries that could deal with file, database, cache, network requests and other I/O operations without blocking.
|
6
6
|
|
7
|
-
If you want to know how midori compares to other libraries/frameworks, checkout out the [
|
7
|
+
If you want to know how midori compares to other libraries/frameworks, checkout out the [Comparison with Other Frameworks](meta/comparison_with_other_frameworks.md)
|
8
8
|
|
9
9
|
## Note
|
10
10
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-midori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HeckPsi Lab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|