em-midori 0.1.4 → 0.1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/em-midori.rb +1 -0
- data/lib/em-midori/core_ext/promise.rb +11 -8
- data/lib/em-midori/core_ext/promise_exception.rb +7 -0
- data/lib/em-midori/extension/postgres.rb +13 -2
- data/lib/em-midori/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8eb56ad166b1af740a4fa22b34129cd1c7d7661d
|
4
|
+
data.tar.gz: e6103dbed135744e21eaaf931ce2dda5e984ae72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09a9e1b5b9661828e276593c224062b672bf5a99a360912143dc2d60df10756b6c9ab45e4841b3f7c9b8a4212709ea5c391a8eb0a256abdd86c4d0a48f35008d
|
7
|
+
data.tar.gz: 245df6e2b0baf5c4c05996d61fd3884e1b725c8b7f76e28424971f24480767edbd38ca249e8e55268fd004de3784b667d6f01651fcb3121a5dc010c3da92997a
|
data/lib/em-midori.rb
CHANGED
@@ -10,6 +10,7 @@ require 'socket'
|
|
10
10
|
require_relative 'em-midori/core_ext/configurable'
|
11
11
|
require_relative 'em-midori/core_ext/string'
|
12
12
|
require_relative 'em-midori/core_ext/promise'
|
13
|
+
require_relative 'em-midori/core_ext/promise_exception'
|
13
14
|
require_relative 'em-midori/core_ext/define_class'
|
14
15
|
require_relative 'em-midori/core_ext/proc'
|
15
16
|
|
@@ -18,13 +18,14 @@ end
|
|
18
18
|
|
19
19
|
class DeferPromise < Promise
|
20
20
|
def initialize(deffered)
|
21
|
-
super(->(resolve,
|
22
|
-
EventMachine.defer(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
super(->(resolve, reject){
|
22
|
+
EventMachine.defer(proc {
|
23
|
+
begin
|
24
|
+
deffered.call
|
25
|
+
rescue Exception => e
|
26
|
+
PromiseException.new(e)
|
27
|
+
end
|
28
|
+
}, proc { |result| resolve.call(result) })
|
28
29
|
})
|
29
30
|
end
|
30
31
|
end
|
@@ -64,6 +65,8 @@ module Kernel
|
|
64
65
|
# @example
|
65
66
|
# result = await SQL.query('SELECT * FROM hello')
|
66
67
|
def await(promise)
|
67
|
-
Fiber.yield promise
|
68
|
+
result = Fiber.yield promise
|
69
|
+
raise result.raw_exception if result.is_a?PromiseException
|
70
|
+
result
|
68
71
|
end
|
69
72
|
end
|
@@ -13,9 +13,20 @@ class Midori::Postgres
|
|
13
13
|
|
14
14
|
def query(sql)
|
15
15
|
await(Promise.new(->(resolve, _reject) {
|
16
|
-
|
17
|
-
|
16
|
+
begin
|
17
|
+
@db.query(sql).callback do |status, result, errors|
|
18
|
+
resolve.call(Midori::Postgres::Result.new(status, result, errors))
|
19
|
+
end
|
18
20
|
end
|
19
21
|
}))
|
20
22
|
end
|
21
23
|
end
|
24
|
+
|
25
|
+
class Midori::Postgres::Result
|
26
|
+
attr_reader :status, :result, :errors
|
27
|
+
def initialize(status, result, errors)
|
28
|
+
@status = status
|
29
|
+
@result = result
|
30
|
+
@errors = errors
|
31
|
+
end
|
32
|
+
end
|
data/lib/em-midori/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-midori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.4
|
4
|
+
version: 0.1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HeckPsi Lab
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/em-midori/core_ext/define_class.rb
|
86
86
|
- lib/em-midori/core_ext/proc.rb
|
87
87
|
- lib/em-midori/core_ext/promise.rb
|
88
|
+
- lib/em-midori/core_ext/promise_exception.rb
|
88
89
|
- lib/em-midori/core_ext/string.rb
|
89
90
|
- lib/em-midori/eventsource.rb
|
90
91
|
- lib/em-midori/exception.rb
|