@@ -294,8 +294,8 @@ public extension Future {
294
294
/// :nodoc:
295
295
@available ( * , deprecated, renamed: " flatMap " )
296
296
func then< NewValue> (
297
- on queue: DispatchQueue = . futures,
298
- callback: @escaping ( _ value: Value ) -> Future < NewValue > ) -> Future < NewValue > {
297
+ on queue: DispatchQueue = . futures,
298
+ callback: @escaping ( _ value: Value ) -> Future < NewValue > ) -> Future < NewValue > {
299
299
flatMap ( on: queue, callback: callback)
300
300
}
301
301
@@ -336,8 +336,8 @@ public extension Future {
336
336
/// :nodoc:
337
337
@available ( * , deprecated, renamed: " flatMapIfRejected " )
338
338
func thenIfRejected(
339
- on queue: DispatchQueue = . futures,
340
- callback: @escaping ( Error ) -> Future < Value > ) -> Future < Value > {
339
+ on queue: DispatchQueue = . futures,
340
+ callback: @escaping ( Error ) -> Future < Value > ) -> Future < Value > {
341
341
flatMapIfRejected ( on: queue, callback: callback)
342
342
}
343
343
@@ -366,8 +366,8 @@ public extension Future {
366
366
/// :nodoc:
367
367
@available ( * , deprecated, renamed: " flatMapThrowing " )
368
368
func thenThrowing< NewValue> (
369
- on queue: DispatchQueue = . futures,
370
- callback: @escaping ( Value ) throws -> NewValue ) -> Future < NewValue > {
369
+ on queue: DispatchQueue = . futures,
370
+ callback: @escaping ( Value ) throws -> NewValue ) -> Future < NewValue > {
371
371
flatMapThrowing ( on: queue, callback: callback)
372
372
}
373
373
@@ -440,6 +440,14 @@ public extension Future {
440
440
func mapIfRejected( on queue: DispatchQueue = . futures, callback: @escaping ( Error ) -> Value ) -> Future < Value > {
441
441
return recover ( on: queue, callback: callback)
442
442
}
443
+
444
+ func print( on queue: DispatchQueue = . futures) -> Future < Value > {
445
+ whenFulfilled { value in
446
+ Swift . print ( value)
447
+ }
448
+
449
+ return self
450
+ }
443
451
}
444
452
445
453
public extension Future {
@@ -492,11 +500,11 @@ public extension Future {
492
500
with combiningFunction: @escaping ( Value , NewValue ) -> Future < Value > ) -> Future < Value >
493
501
where S. Element == Future < NewValue > {
494
502
495
- return futures. reduce ( self ) { future1, future2 in
496
- return future1. and ( future2, on: queue) . flatMap ( on: queue) { value1, value2 in
497
- return combiningFunction ( value1, value2)
503
+ return futures. reduce ( self ) { future1, future2 in
504
+ return future1. and ( future2, on: queue) . flatMap ( on: queue) { value1, value2 in
505
+ return combiningFunction ( value1, value2)
506
+ }
498
507
}
499
- }
500
508
}
501
509
502
510
/// Returns a new `Future<Value>` that fires only when all the provided `Future<NewValue>`s have been resolved.
@@ -521,11 +529,11 @@ public extension Future {
521
529
nextPartialResult: @escaping ( Value , NewValue ) -> Value ) -> Future < Value >
522
530
where S. Element == Future < NewValue > {
523
531
524
- let initialResult = Future < Value > ( fulfilledWith: initialResult)
532
+ let initialResult = Future < Value > ( fulfilledWith: initialResult)
525
533
526
- return initialResult. fold ( futures, on: queue) { value1, value2 in
527
- return Future ( fulfilledWith: nextPartialResult ( value1, value2) )
528
- }
534
+ return initialResult. fold ( futures, on: queue) { value1, value2 in
535
+ return Future ( fulfilledWith: nextPartialResult ( value1, value2) )
536
+ }
529
537
}
530
538
531
539
/// Returns a new `Future<Value>` that will resolve with result of this `Future` **after**
@@ -599,18 +607,9 @@ public extension Future {
599
607
/// - Returns: A future that will receive the eventual value.
600
608
@discardableResult
601
609
func discard( on queue: DispatchQueue = . futures) -> Future < Void > {
602
-
603
- let promise = Promise < Void > ( )
604
-
605
- whenFulfilled ( on: queue) { _ in
606
- promise. fulfill ( )
607
- }
608
-
609
- whenRejected { error in
610
- promise. reject ( error)
610
+ map ( on: queue) { _ in
611
+ return ( )
611
612
}
612
-
613
- return promise. future
614
613
}
615
614
}
616
615
0 commit comments