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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5a62c03f0e31bd0ea7466d2ddda81f2fbdd8efd
4
- data.tar.gz: c16d4d64ce2fd066ccd7bef0546bd07a816a7ac0
3
+ metadata.gz: 0e4238511fe308c3529be24fbad1cd44b3e436cc
4
+ data.tar.gz: 9a01e07793ec3b2f72fd2e43f2609aba482798dd
5
5
  SHA512:
6
- metadata.gz: d8c6e274f821b8f2f4f3ef746e98b1b5efe2d1774d67a55e7083271ab5fb51928e71cdb2df4f19fe2a7e5d7ac62293ce728525b87b3d76ff2ac37e4f6b95d18c
7
- data.tar.gz: ce6a571451d2a7647872135c2546fc097fb86667b4888b5ddfe6cd54374989964bcc5530c58d8466401956ed4959bba6634bbb298b32ce63cedf88b852f63c78
6
+ metadata.gz: 336b392c12a61aafa8538d3d6cad03e7c7c1559432faf4dc879d4dfc16dd0bff2a69822a20e52f79f2fc1fb7198d6bf05111cccf4f57aecf866673ec1f94be4e
7
+ data.tar.gz: 4714ff8b26be8dcf63fea4f8386cc7c1d0ed200f64058dd9707f945470bc34e024c1b2c2e22ed3c9b0252f4153bfe65324f2ad6b914ebac709da431e32f95768
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016
3
+ Copyright (c) 2016-2017 HeckPsi Lab
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -2,21 +2,26 @@
2
2
  # EventLoop Module, providing main loop for events
3
3
  module EventLoop
4
4
  class << self
5
- # Raw NIO Selector
6
- SELECTOR = NIO::Selector.new
7
- # Array of active timers
8
- TIMERS = []
9
- # Hash of io and its callback
10
- IOS = Hash.new
11
- # IO queue
12
- QUEUE = Hash.new
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
- TIMERS << timer
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 QUEUE[io.to_i].nil?
30
- QUEUE[io.to_i] = Array.new
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
- QUEUE[io.to_i] << [io, interest, callback]
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
- SELECTOR.register(io, interest)
45
- IOS[io] = { callback: callback }
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
- SELECTOR.deregister(io)
55
- IOS.delete(io)
56
- next_register = QUEUE[fd].shift
57
- next_register.nil? ? QUEUE.delete(fd) : register_raw(*next_register)
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
- SELECTOR.select(0.2) do |monitor| # Timeout for 0.2 secs
65
- IOS[monitor.io][:callback].call(monitor)
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
- EventLoop.timer_once
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
- TIMERS.delete_if do |timer|
83
+ @timers.delete_if do |timer|
76
84
  if timer.start_time < now_time
77
85
  timer.callback.call
78
86
  true
@@ -1,5 +1,5 @@
1
1
  # Midori Module
2
2
  module Midori
3
3
  # Current Version Code
4
- VERSION = '0.2.1'.freeze
4
+ VERSION = '0.2.2'.freeze
5
5
  end
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 [Compatison with Other Frameworks](meta/comparison_with_other_frameworks.md)
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.1
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-02 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r