em-midori 0.1.2 → 0.1.3
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/core_ext/promise.rb +18 -1
- data/lib/em-midori/extension/file.rb +19 -0
- 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: 63375f6e8a60a297804f655301642f3a4301bae3
|
4
|
+
data.tar.gz: 7862191b4a720a0568759b8a325eec7f6e4d6277
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea4d98047259403a5c37ca083639a72b93612cc37e1879a2deecee2a2abca4aaccf25922df172d5a48750fea1cec614b4ccd07f5eddc85ea262d58e5d3d9971d
|
7
|
+
data.tar.gz: c4860155f3ae3a2ae0861604c637c36fbe883d6a633e5bfa744fbafbd9db59c31945e8c5c1b278e74947375ff075dfa50944d548d18070ac6801bfb26a0ff610
|
@@ -16,12 +16,25 @@ class Promise
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
class DeferPromise < Promise
|
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
|
+
})
|
28
|
+
})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
19
32
|
module Kernel
|
20
33
|
# Logic dealing of async method
|
21
34
|
# @param [Fiber] fiber a fiber to call
|
22
35
|
def async_internal(fiber)
|
23
36
|
chain = lambda do |result|
|
24
|
-
return
|
37
|
+
return unless result.is_a?Promise
|
25
38
|
result.then(lambda do |val|
|
26
39
|
chain.call(fiber.resume(val))
|
27
40
|
end)
|
@@ -42,6 +55,10 @@ module Kernel
|
|
42
55
|
}
|
43
56
|
end
|
44
57
|
|
58
|
+
def defer(&block)
|
59
|
+
DeferPromise.new(block)
|
60
|
+
end
|
61
|
+
|
45
62
|
# Block the I/O to wait for async method response
|
46
63
|
# @param [Promise] promise promise method
|
47
64
|
# @example
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Midori::File
|
2
|
+
class << self
|
3
|
+
def read_promise(*args)
|
4
|
+
defer { File.read(*args) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def read(*args)
|
8
|
+
await read_promise(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def write_promise(*args)
|
12
|
+
defer { File.write(*args) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(*args)
|
16
|
+
await write_promise(*args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
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
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HeckPsi Lab
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/em-midori/core_ext/string.rb
|
75
75
|
- lib/em-midori/error.rb
|
76
76
|
- lib/em-midori/eventsource.rb
|
77
|
+
- lib/em-midori/extension/file.rb
|
77
78
|
- lib/em-midori/middleware.rb
|
78
79
|
- lib/em-midori/request.rb
|
79
80
|
- lib/em-midori/response.rb
|