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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cde61e335c329326e0e04c9d2e433077923260ed
4
- data.tar.gz: f866ca5439372bde2d084e4cded2f66c27283904
3
+ metadata.gz: 8eb56ad166b1af740a4fa22b34129cd1c7d7661d
4
+ data.tar.gz: e6103dbed135744e21eaaf931ce2dda5e984ae72
5
5
  SHA512:
6
- metadata.gz: 93593618d3d46c284937ad42d1fce33e4fe7375644717744773b537fd1c8a8e9717b86334f5b968c4388b9fd40daece5a94b2b0ce5e9f9d89cd6c61cfd12916f
7
- data.tar.gz: 28a9dae73071f578989377e7e312606a7a88feada47057b264e4e7363dbe1a5b3162f8c2926fd393d5208db769d4cf91c643590e1b588b5c22636f6e17810637
6
+ metadata.gz: 09a9e1b5b9661828e276593c224062b672bf5a99a360912143dc2d60df10756b6c9ab45e4841b3f7c9b8a4212709ea5c391a8eb0a256abdd86c4d0a48f35008d
7
+ data.tar.gz: 245df6e2b0baf5c4c05996d61fd3884e1b725c8b7f76e28424971f24480767edbd38ca249e8e55268fd004de3784b667d6f01651fcb3121a5dc010c3da92997a
@@ -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, _reject){
22
- EventMachine.defer(deffered,
23
- proc { |result|
24
- resolve.call(result)
25
- }, proc { |error|
26
- raise error
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
@@ -0,0 +1,7 @@
1
+ class PromiseException < StandardError
2
+ attr_reader :raw_exception
3
+ def initialize(raw_exception)
4
+ super(nil)
5
+ @raw_exception = raw_exception
6
+ end
7
+ end
@@ -13,9 +13,20 @@ class Midori::Postgres
13
13
 
14
14
  def query(sql)
15
15
  await(Promise.new(->(resolve, _reject) {
16
- @db.query(sql).callback do |status, result, errors|
17
- status ? resolve.call(result) : (puts errors; raise RuntimeError)
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
@@ -1,5 +1,5 @@
1
1
  # Midori Module
2
2
  module Midori
3
3
  # Current Version Code
4
- VERSION = '0.1.4'.freeze
4
+ VERSION = '0.1.4.1'.freeze
5
5
  end
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