Skip to content

Commit 72740c1

Browse files
committed
Merge branch 'master' into reactive-swift
2 parents cc311c0 + 574e131 commit 72740c1

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ReactiveSwift/SignalProducer.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,22 @@ extension SignalProducerProtocol where Error == NoError {
11761176
) -> SignalProducer<Value, NewError> {
11771177
return lift { $0.timeout(after: interval, raising: error, on: scheduler) }
11781178
}
1179+
1180+
/// Wait for completion of `self`, *then* forward all events from
1181+
/// `replacement`.
1182+
///
1183+
/// - note: All values sent from `self` are ignored.
1184+
///
1185+
/// - parameters:
1186+
/// - replacement: A producer to start when `self` completes.
1187+
///
1188+
/// - returns: A producer that sends events from `self` and then from
1189+
/// `replacement` when `self` completes.
1190+
public func then<U, NewError: Swift.Error>(_ replacement: SignalProducer<U, NewError>) -> SignalProducer<U, NewError> {
1191+
return self
1192+
.promoteErrors(NewError.self)
1193+
.then(replacement)
1194+
}
11791195
}
11801196

11811197
extension SignalProducerProtocol where Value: Equatable {
@@ -1576,6 +1592,22 @@ extension SignalProducerProtocol {
15761592
}
15771593
}
15781594

1595+
/// Wait for completion of `self`, *then* forward all events from
1596+
/// `replacement`. Any failure or interruption sent from `self` is
1597+
/// forwarded immediately, in which case `replacement` will not be started,
1598+
/// and none of its events will be be forwarded.
1599+
///
1600+
/// - note: All values sent from `self` are ignored.
1601+
///
1602+
/// - parameters:
1603+
/// - replacement: A producer to start when `self` completes.
1604+
///
1605+
/// - returns: A producer that sends events from `self` and then from
1606+
/// `replacement` when `self` completes.
1607+
public func then<U>(_ replacement: SignalProducer<U, NoError>) -> SignalProducer<U, Error> {
1608+
return self.then(replacement.promoteErrors(Error.self))
1609+
}
1610+
15791611
/// Start the producer, then block, waiting for the first value.
15801612
///
15811613
/// When a single value or error is sent, the returned `Result` will

ReactiveSwiftTests/SignalProducerSpec.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,27 @@ class SignalProducerSpec: QuickSpec {
16671667
subsequentObserver.sendCompleted()
16681668
expect(completed) == true
16691669
}
1670+
1671+
it("works with NoError and TestError") {
1672+
let producer: SignalProducer<Int, TestError> = SignalProducer<Int, NoError>.empty
1673+
.then(SignalProducer<Int, TestError>.empty)
1674+
1675+
_ = producer
1676+
}
1677+
1678+
it("works with TestError and NoError") {
1679+
let producer: SignalProducer<Int, TestError> = SignalProducer<Int, TestError>.empty
1680+
.then(SignalProducer<Int, NoError>.empty)
1681+
1682+
_ = producer
1683+
}
1684+
1685+
it("works with NoError and NoError") {
1686+
let producer: SignalProducer<Int, NoError> = SignalProducer<Int, NoError>.empty
1687+
.then(SignalProducer<Int, NoError>.empty)
1688+
1689+
_ = producer
1690+
}
16701691
}
16711692

16721693
describe("first") {

0 commit comments

Comments
 (0)