emmy-machine 0.1.3 → 0.1.5

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: cbcf6dad55c2c829b3c317639952d0b1d1a73cd9
4
- data.tar.gz: 2df6741e6561736c9065ffa3a816d88a9cdef981
3
+ metadata.gz: 99d71ea2901f9ad585420efdee4096534b361c5b
4
+ data.tar.gz: 009e015cac2681f1ac436817f75a2a8f15c566d8
5
5
  SHA512:
6
- metadata.gz: b9242b823d1f132e80dadc98382f09642c788ff0398142ea5ac9aa9a2c230a909d8b3b490dca89ae52333f91c64fe5b9e1b2a69fe9aad81e54fac6ff84a4cfbe
7
- data.tar.gz: 8ca89dede626c70cf4c00b266cacf819ba3dac7cdf6618056c7f02f8a2ed2603c2de3fcf362c0362c8998f5daa90fa8171ad3f0ad40efd3dcf032ebf2f4b23fb
6
+ metadata.gz: 010e869e2d7f6d5a238afaa3863ee84238ae72d579f8f6d46a59358a9eef9174776e5b2b9e46603e9772c574d360e94e3c2020ba136976a96a3c0d58bedfe5bd
7
+ data.tar.gz: 2ff7ef33ca294342a684af673dd387edd7abcf8306a53f7585653d02cba5f4bf2a5b06c7bc5f23f022473d65bf895df79ea62fa6284615b0b6d887345eacace8
data/emmy_machine.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "eventmachine", "~> 1.0.3"
22
- spec.add_dependency "fibre", "~> 0.9.0"
22
+ spec.add_dependency "fibre", "~> 0.9"
23
+ #spec.add_dependency "emmy-engine", "~> 0.1.0"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.6"
25
26
  spec.add_development_dependency "rspec", "~> 3"
@@ -19,8 +19,11 @@ module EmmyMachine
19
19
  def run_block &b
20
20
  EventMachine.run do
21
21
  fiber_block do
22
- yield
23
- EventMachine.stop
22
+ begin
23
+ yield
24
+ ensure
25
+ stop
26
+ end
24
27
  end
25
28
  end
26
29
  end
@@ -50,17 +53,17 @@ module EmmyMachine
50
53
  end
51
54
 
52
55
  #
53
- # Connect to server
56
+ # Connect to remote server
54
57
  #
55
- # emmy.connect("tcp://localhost:5555")
56
- # emmy.connect("ipc://mypoint")
57
- # emmy.connect("tcp://localhost:5555", handler, *args)
58
- # emmy.connect(*emmy.http.get(url))
58
+ # EmmyMachine.connect("tcp://localhost:5555")
59
+ # EmmyMachine.connect("ipc://mypoint")
60
+ # EmmyMachine.connect("tcp://localhost:5555", handler, *args)
61
+ # EmmyMachine.connect(*emmy.http.get(url))
59
62
  def connect(url, *a, &b)
60
63
  url = URI(url.to_s)
61
64
  handler = a.empty? ? Connection : a.shift
62
65
  b ||= a.shift if a.first.is_a?(Proc) || a.first.is_a?(Method)
63
-
66
+
64
67
  case url.scheme
65
68
  when "tcp" then
66
69
  EventMachine.connect(url.host, url.port, handler, *a, &b)
@@ -72,11 +75,11 @@ module EmmyMachine
72
75
  end
73
76
 
74
77
  #
75
- # Start server
78
+ # Bind server
76
79
  #
77
- # emmy.bind("tcp://localhost:5555", ServerConnection)
78
- # emmy.bind("ipc://mypoint", ServerConnection)
79
- # emmy.bind(* emmy.server.thin("tcp://localhost:4780", app))
80
+ # EmmyMachine.bind("tcp://localhost:5555", ServerConnection)
81
+ # EmmyMachine.bind("ipc://mypoint", ServerConnection)
82
+ # emmy.bind(*emmy.server.thin("tcp://localhost:4780", app))
80
83
  def bind(url, *a, &b)
81
84
  url = URI(url.to_s)
82
85
  handler = a.empty? ? Connection : a.shift
@@ -92,6 +95,16 @@ module EmmyMachine
92
95
  end
93
96
  end
94
97
 
98
+ #
99
+ # Watch socket
100
+ #
101
+ # EmmyMachine.watch(socket, ClientConnection) - notify read by default
102
+ # EmmyMachine.watch(socket, ClientConnection, notify_readable: false, notify_writable: true) - notify write only
103
+ def watch(socket, handler, *a, notify_readable: true, notify_writable: false, &b)
104
+ b ||= a.shift if a.first.is_a?(Proc) || a.first.is_a?(Method)
105
+ EventMachine::attach_io(socket, true, handler, *a, &b)
106
+ end
107
+
95
108
  def next_tick
96
109
  fiber = Fiber.current
97
110
  EventMachine.next_tick { fiber.resume }
@@ -3,10 +3,13 @@ module EmmyMachine
3
3
  using EventObject
4
4
 
5
5
  def self.included(base)
6
- base.events :connect, :data, :close, :error
6
+ base.events :init, :connect, :data, :close, :error, :handshake, :verify_peer
7
7
  base.class_eval do
8
+ alias_method :post_init, :init!
8
9
  alias_method :connection_completed, :connect!
9
10
  alias_method :receive_data, :data!
11
+ alias_method :ssl_handshake_completed, :handshake!
12
+ alias_method :ssl_verify_peer, :verify_peer!
10
13
  end
11
14
  end
12
15
 
@@ -0,0 +1,20 @@
1
+ module Emmy
2
+ class Deferred
3
+ using EventObject
4
+ events :success, :error
5
+
6
+ def sync
7
+ Fiber.sync do |fiber|
8
+ on :success do |response|
9
+ fiber.resume response
10
+ end
11
+
12
+ on :error do |error|
13
+ fiber.leave error
14
+ end
15
+ end
16
+ end
17
+
18
+ #<<<
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module EmmyMachine
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,15 @@
1
+ module EmmyMachine
2
+ module Watcher
3
+ using EventObject
4
+
5
+ def self.included(base)
6
+ base.events :read, :write
7
+ base.class_eval do
8
+ alias_method :notify_readable, :read!
9
+ alias_method :notify_writable, :write!
10
+ end
11
+ end
12
+
13
+ #<<<
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emmy-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Che
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-16 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.0
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.0
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +96,9 @@ files:
96
96
  - lib/emmy_machine.rb
97
97
  - lib/emmy_machine/class_methods.rb
98
98
  - lib/emmy_machine/connection.rb
99
+ - lib/emmy_machine/deferred.rb
99
100
  - lib/emmy_machine/version.rb
101
+ - lib/emmy_machine/watcher.rb
100
102
  - spec/emmy_machine_spec.rb
101
103
  - spec/spec_helper.rb
102
104
  homepage: ''