@@ -13,15 +13,17 @@ module Concurrent
13
13
let! ( :rejected_reason ) { StandardError . new ( 'mojo jojo' ) }
14
14
15
15
let ( :pending_subject ) do
16
- Promise . new ( executor : executor ) { sleep ( 0.1 ) ; fulfilled_value } . execute
16
+ executor = Concurrent ::SingleThreadExecutor . new
17
+ executor . post { sleep ( 5 ) }
18
+ Promise . execute ( executor : executor ) { fulfilled_value }
17
19
end
18
20
19
21
let ( :fulfilled_subject ) do
20
- Promise . fulfill ( fulfilled_value , executor : executor )
22
+ Promise . new ( executor : executor ) { fulfilled_value } . execute . tap { sleep ( 0.1 ) }
21
23
end
22
24
23
25
let ( :rejected_subject ) do
24
- Promise . reject ( rejected_reason , executor : executor )
26
+ Promise . new ( executor : executor ) { raise rejected_reason } . execute . tap { sleep ( 0.1 ) }
25
27
end
26
28
27
29
it_should_behave_like :ivar do
@@ -149,13 +151,21 @@ def get_ivar_from_args(opts)
149
151
context 'pending' do
150
152
151
153
it 'sets the promise to :pending' do
152
- p = pending_subject . execute
154
+ latch = CountDownLatch . new
155
+ p = Promise . new { latch . wait ( 1 ) } . execute
153
156
expect ( p ) . to be_pending
157
+ latch . count_down
154
158
end
155
159
156
- it 'does not posts again' do
160
+ it 'does not post again' do
161
+ executor = SimpleExecutorService . new
157
162
expect ( executor ) . to receive ( :post ) . with ( any_args ) . once
158
- pending_subject . execute
163
+
164
+ latch = CountDownLatch . new
165
+ p = Promise . new ( executor : executor ) { latch . wait ( 1 ) } . execute
166
+
167
+ 10 . times { p . execute }
168
+ latch . count_down
159
169
end
160
170
end
161
171
0 commit comments