File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,11 @@ class Promise
12
12
# @see http://wiki.commonjs.org/wiki/Promises/A
13
13
# @see http://promises-aplus.github.io/promises-spec/
14
14
def initialize ( options = { } , &block )
15
+ options . delete_if { |k , v | v . nil? }
16
+
15
17
@parent = options . fetch ( :parent ) { nil }
16
18
@on_fulfill = options . fetch ( :on_fulfill ) { Proc . new { |result | result } }
17
- @on_reject = options . fetch ( :on_reject ) { Proc . new { |result | result } }
19
+ @on_reject = options . fetch ( :on_reject ) { Proc . new { |reason | raise reason } }
18
20
19
21
@promise_body = block || Proc . new { |result | result }
20
22
@state = :unscheduled
Original file line number Diff line number Diff line change @@ -307,6 +307,12 @@ module Concurrent
307
307
expected . should eq 20
308
308
end
309
309
310
+ it 'uses result as fulfillment value when a promise has no block' do
311
+ p = Promise . new { 20 } . then ( Proc . new { } ) . execute
312
+ sleep ( 0.1 )
313
+ p . value . should eq 20
314
+ end
315
+
310
316
it 'can manage long chain' do
311
317
root = Promise . new { 20 }
312
318
p1 = root . then { |b | b * 3 }
@@ -345,6 +351,13 @@ module Concurrent
345
351
p . should be_rejected
346
352
end
347
353
354
+ it 'uses reason as rejection reason when a promise has no rescue callable' do
355
+ p = Promise . new { raise ArgumentError } . then { |val | val } . execute
356
+ sleep ( 0.1 )
357
+ p . should be_rejected
358
+ p . reason . should be_a ArgumentError
359
+ end
360
+
348
361
end
349
362
350
363
context 'aliases' do
You can’t perform that action at this time.
0 commit comments