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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f38d205f0e4f20a31cfdec6103d2f51367dc4f8
4
- data.tar.gz: 5edb796b384fdf26b0f2ad2e1e4c7d4ff74308b4
3
+ metadata.gz: 63375f6e8a60a297804f655301642f3a4301bae3
4
+ data.tar.gz: 7862191b4a720a0568759b8a325eec7f6e4d6277
5
5
  SHA512:
6
- metadata.gz: c1fb15aa76bac728a030b5f2989c401cddd29a279505fd51c9b52c6c74c3c00759336edcc091cc864b7f3cab060de7bbf7de3c0e77cc2019e62e4cc48cee3f15
7
- data.tar.gz: c3dd1c67a230b4a3de6d5b7e1a41d225021728c50951d4993703c1579d2e2c18086bd5ec8ba144023acdff81c403938b4b2c3a00a5be43f2f2422461ac511fcb
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 if result.class != Promise
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
@@ -1,5 +1,5 @@
1
1
  # Midori Module
2
2
  module Midori
3
3
  # Current Version Code
4
- VERSION = '0.1.2'.freeze
4
+ VERSION = '0.1.3'.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.2
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