Skip to content

Commit f92da49

Browse files
committed
Revert a few overloads to the protocol to mitigate an overloading issue.
1 parent c88f907 commit f92da49

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

Sources/SignalProducer.swift

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,22 +1259,6 @@ extension SignalProducer where Error == NoError {
12591259
return lift { $0.timeout(after: interval, raising: error, on: scheduler) }
12601260
}
12611261

1262-
/// Wait for completion of `self`, *then* forward all events from
1263-
/// `replacement`.
1264-
///
1265-
/// - note: All values sent from `self` are ignored.
1266-
///
1267-
/// - parameters:
1268-
/// - replacement: A producer to start when `self` completes.
1269-
///
1270-
/// - returns: A producer that sends events from `self` and then from
1271-
/// `replacement` when `self` completes.
1272-
public func then<U, NewError: Swift.Error>(_ replacement: SignalProducer<U, NewError>) -> SignalProducer<U, NewError> {
1273-
return self
1274-
.promoteErrors(NewError.self)
1275-
.then(replacement)
1276-
}
1277-
12781262
/// Apply a failable `operation` to values from `self` with successful
12791263
/// results forwarded on the returned producer and thrown errors sent as
12801264
/// failed events.
@@ -1317,8 +1301,8 @@ extension SignalProducer {
13171301
/// - returns: A `SignalProducer` that will forward `success`ful `result` as
13181302
/// `value` event and then complete or `failed` event if `result`
13191303
/// is a `failure`.
1320-
public static func attempt(_ operation: @escaping () -> Result<Value, Error>) -> SignalProducer {
1321-
return self.init { observer, disposable in
1304+
public static func attempt(_ operation: @escaping () -> Result<Value, Error>) -> SignalProducer<Value, Error> {
1305+
return SignalProducer<Value, Error> { observer, disposable in
13221306
operation().analysis(ifSuccess: { value in
13231307
observer.send(value: value)
13241308
observer.sendCompleted()
@@ -1329,7 +1313,13 @@ extension SignalProducer {
13291313
}
13301314
}
13311315

1332-
extension SignalProducer where Error == AnyError {
1316+
// FIXME: SWIFT_COMPILER_ISSUE
1317+
//
1318+
// One of the `SignalProducer.attempt` overloads is kept in the protocol to
1319+
// mitigate an overloading issue. Moving them back to the concrete type would be
1320+
// a binary-breaking, source-compatible change.
1321+
1322+
extension SignalProducerProtocol where Error == AnyError {
13331323
/// Create a `SignalProducer` that will attempt the given failable operation once for
13341324
/// each invocation of `start()`.
13351325
///
@@ -1342,14 +1332,16 @@ extension SignalProducer where Error == AnyError {
13421332
///
13431333
/// - returns: A `SignalProducer` that will forward a success as a `value`
13441334
/// event and then complete or `failed` event if the closure throws.
1345-
public static func attempt(_ operation: @escaping () throws -> Value) -> SignalProducer<Value, Error> {
1335+
public static func attempt(_ operation: @escaping () throws -> Value) -> SignalProducer<Value, AnyError> {
13461336
return .attempt {
13471337
ReactiveSwift.materialize {
13481338
try operation()
13491339
}
13501340
}
13511341
}
1342+
}
13521343

1344+
extension SignalProducer where Error == AnyError {
13531345
/// Apply a failable `operation` to values from `self` with successful
13541346
/// results forwarded on the returned producer and thrown errors sent as
13551347
/// failed events.
@@ -1777,7 +1769,15 @@ extension SignalProducer {
17771769
}
17781770
}
17791771
}
1772+
}
1773+
1774+
// FIXME: SWIFT_COMPILER_ISSUE
1775+
//
1776+
// Two of the `SignalProducer.then(self:_:)` overloads are kept in the protocol
1777+
// to mitigate an overloading issue. Moving them back to the concrete type would
1778+
// be a binary-breaking, source-compatible change.
17801779

1780+
extension SignalProducerProtocol {
17811781
/// Wait for completion of `self`, *then* forward all events from
17821782
/// `replacement`. Any failure or interruption sent from `self` is
17831783
/// forwarded immediately, in which case `replacement` will not be started,
@@ -1791,9 +1791,30 @@ extension SignalProducer {
17911791
/// - returns: A producer that sends events from `self` and then from
17921792
/// `replacement` when `self` completes.
17931793
public func then<U>(_ replacement: SignalProducer<U, NoError>) -> SignalProducer<U, Error> {
1794-
return self.then(replacement.promoteErrors(Error.self))
1794+
return self.producer.then(replacement.promoteErrors(Error.self))
17951795
}
1796+
}
17961797

1798+
extension SignalProducerProtocol where Error == NoError {
1799+
/// Wait for completion of `self`, *then* forward all events from
1800+
/// `replacement`.
1801+
///
1802+
/// - note: All values sent from `self` are ignored.
1803+
///
1804+
/// - parameters:
1805+
/// - replacement: A producer to start when `self` completes.
1806+
///
1807+
/// - returns: A producer that sends events from `self` and then from
1808+
/// `replacement` when `self` completes.
1809+
public func then<U, NewError: Swift.Error>(_ replacement: SignalProducer<U, NewError>) -> SignalProducer<U, NewError> {
1810+
return self
1811+
.producer
1812+
.promoteErrors(NewError.self)
1813+
.then(replacement)
1814+
}
1815+
}
1816+
1817+
extension SignalProducer {
17971818
/// Start the producer, then block, waiting for the first value.
17981819
///
17991820
/// When a single value or error is sent, the returned `Result` will

0 commit comments

Comments
 (0)