async-rack 0.4.0.b → 0.4.0.c

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,7 +72,27 @@ module AsyncRack
72
72
  end
73
73
  end
74
74
 
75
+ module LateInitializer
76
+ def included(klass)
77
+ setup_late_initialize klass if klass.is_a? Class
78
+ klass.extend LateInitializer
79
+ super
80
+ end
81
+
82
+ private
83
+ def setup_late_initialize(klass)
84
+ class << klass
85
+ alias create new
86
+ def new(*args, &block)
87
+ proc { |env| create(*args, &block).call(env) }
88
+ end
89
+ end
90
+ end
91
+ end
92
+
75
93
  module Mixin
94
+ extend LateInitializer
95
+
76
96
  def async_callback(result)
77
97
  @async_callback.call result
78
98
  end
@@ -25,16 +25,26 @@ describe AsyncRack::AsyncCallback do
25
25
  end
26
26
 
27
27
  describe :SimpleWrapper do
28
- it "runs #call again on async callback, replacing app" do
29
- klass = Class.new do
28
+ before do
29
+ @class = Class.new do
30
30
  include AsyncRack::AsyncCallback::SimpleWrapper
31
31
  attr_accessor :app, :env
32
+ class << self
33
+ attr_accessor :instance
34
+ end
35
+ def initialize(app = nil)
36
+ self.class.instance = self
37
+ @app = app
38
+ end
32
39
  def call(env)
33
40
  setup_async env
34
41
  @app.call(env) + 5
35
42
  end
36
43
  end
37
- middleware = klass.new
44
+ end
45
+
46
+ it "runs #call again on async callback, replacing app" do
47
+ middleware = @class.create
38
48
  middleware.app = proc { throw :async }
39
49
  catch(:async) do
40
50
  middleware.call "async.callback" => proc { |x| x + 10 }
@@ -42,6 +52,26 @@ describe AsyncRack::AsyncCallback do
42
52
  end
43
53
  middleware.env["async.callback"].call(0).should == 15
44
54
  end
55
+
56
+ it "plays well with Rack::Builder" do
57
+ klass = @class
58
+ app = Rack::Builder.app do
59
+ use klass
60
+ run lambda { |env|
61
+ return 37 if @threw
62
+ @threw = true
63
+ throw :async
64
+ }
65
+ end
66
+ catch(:async) do
67
+ app.call "async.callback" => proc { |x| x + 10 }
68
+ raise "should not get here"
69
+ end
70
+ @class.instance.env["async.callback"].call(0).should == 15
71
+ @class.instance.env["async.callback"].call(10).should == 25
72
+ result = app.call "async.callback" => proc { |x| x + 10 }
73
+ result.should == 42
74
+ end
45
75
  end
46
76
 
47
77
  describe :Mixin do
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 4
8
8
  - 0
9
- - b
10
- version: 0.4.0.b
9
+ - c
10
+ version: 0.4.0.c
11
11
  platform: ruby
12
12
  authors:
13
13
  - Konstantin Haase
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-03-09 00:00:00 +01:00
18
+ date: 2010-03-12 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency