Skip to content

Commit a3e95ef

Browse files
committed
Change indentation
1 parent cff128f commit a3e95ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2751
-2743
lines changed

Package.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
import PackageDescription
33

44
var package = Package(
5-
name: "Conbini",
6-
platforms: [
7-
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)
8-
],
9-
products: [
10-
.library(name: "Conbini", targets: ["Conbini"]),
11-
.library(name: "ConbiniForTesting", targets: ["ConbiniForTesting"])
12-
],
13-
dependencies: [],
14-
targets: [
15-
.target(name: "Conbini", path: "sources/runtime"),
16-
.target(name: "ConbiniForTesting", path: "sources/testing"),
17-
.testTarget(name: "ConbiniTests", dependencies: ["Conbini"], path: "tests/runtime"),
18-
.testTarget(name: "ConbiniForTestingTests", dependencies: ["Conbini", "ConbiniForTesting"], path: "tests/testing"),
19-
]
5+
name: "Conbini",
6+
platforms: [
7+
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)
8+
],
9+
products: [
10+
.library(name: "Conbini", targets: ["Conbini"]),
11+
.library(name: "ConbiniForTesting", targets: ["ConbiniForTesting"])
12+
],
13+
dependencies: [],
14+
targets: [
15+
.target(name: "Conbini", path: "sources/runtime"),
16+
.target(name: "ConbiniForTesting", path: "sources/testing"),
17+
.testTarget(name: "ConbiniTests", dependencies: ["Conbini"], path: "tests/runtime"),
18+
.testTarget(name: "ConbiniForTestingTests", dependencies: ["Conbini", "ConbiniForTesting"], path: "tests/testing"),
19+
]
2020
)
Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,97 @@
11
import Combine
22

33
extension Publisher where Self.Failure==Never {
4-
/// Assigns a publisher's output to a property of an object.
5-
///
6-
/// The difference between `assign(to:onWeak:)` and Combine's `assign(to:on:)` is two-fold:
7-
/// - `assign(to:onWeak:)` doesn't set a _strong bond_ to `object`.
8-
/// This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
9-
/// - `assign(to:onWeak:)` cancels the upstream publisher if it detects `object` is deinitialized.
10-
///
11-
/// The difference between is that a _strong bond_ is not set to the`object`. This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
12-
/// - parameter keyPath: A key path that indicates the property to assign.
13-
/// - parameter object: The object that contains the property. The subscriber assigns the object's property every time it receives a new value.
14-
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically assign the property. Deinitializing this instance will also cancel automatic assignment.
15-
@_transparent public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root,Output>, onWeak object: Root) -> AnyCancellable where Root:AnyObject {
16-
weak var cancellable: AnyCancellable? = nil
17-
let cleanup: (Subscribers.Completion<Never>) -> Void = { _ in
18-
cancellable?.cancel()
19-
cancellable = nil
20-
}
21-
22-
let subscriber = Subscribers.Sink<Output,Never>(receiveCompletion: cleanup, receiveValue: { [weak object] (value) in
23-
guard let object = object else { return cleanup(.finished) }
24-
object[keyPath: keyPath] = value
25-
})
26-
27-
let result = AnyCancellable(subscriber)
28-
cancellable = result
29-
self.subscribe(subscriber)
30-
return result
31-
}
32-
33-
/// Assigns a publisher's output to a property of an object.
34-
///
35-
/// The difference between `assign(to:onUnowned:)` and Combine's `assign(to:on:)` is that a _strong bond_ is not set to the`object`. This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
36-
/// - parameter keyPath: A key path that indicates the property to assign.
37-
/// - parameter object: The object that contains the property. The subscriber assigns the object's property every time it receives a new value.
38-
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically assign the property. Deinitializing this instance will also cancel automatic assignment.
39-
@_transparent public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root,Output>, onUnowned object: Root) -> AnyCancellable where Root:AnyObject {
40-
self.sink(receiveValue: { [unowned object] (value) in
41-
object[keyPath: keyPath] = value
42-
})
4+
/// Assigns a publisher's output to a property of an object.
5+
///
6+
/// The difference between `assign(to:onWeak:)` and Combine's `assign(to:on:)` is two-fold:
7+
/// - `assign(to:onWeak:)` doesn't set a _strong bond_ to `object`.
8+
/// This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
9+
/// - `assign(to:onWeak:)` cancels the upstream publisher if it detects `object` is deinitialized.
10+
///
11+
/// The difference between is that a _strong bond_ is not set to the`object`. This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
12+
/// - parameter keyPath: A key path that indicates the property to assign.
13+
/// - parameter object: The object that contains the property. The subscriber assigns the object's property every time it receives a new value.
14+
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically assign the property. Deinitializing this instance will also cancel automatic assignment.
15+
@_transparent public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root,Output>, onWeak object: Root) -> AnyCancellable where Root:AnyObject {
16+
weak var cancellable: AnyCancellable? = nil
17+
let cleanup: (Subscribers.Completion<Never>) -> Void = { _ in
18+
cancellable?.cancel()
19+
cancellable = nil
4320
}
21+
22+
let subscriber = Subscribers.Sink<Output,Never>(receiveCompletion: cleanup, receiveValue: { [weak object] (value) in
23+
guard let object = object else { return cleanup(.finished) }
24+
object[keyPath: keyPath] = value
25+
})
26+
27+
let result = AnyCancellable(subscriber)
28+
cancellable = result
29+
self.subscribe(subscriber)
30+
return result
31+
}
32+
33+
/// Assigns a publisher's output to a property of an object.
34+
///
35+
/// The difference between `assign(to:onUnowned:)` and Combine's `assign(to:on:)` is that a _strong bond_ is not set to the`object`. This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
36+
/// - parameter keyPath: A key path that indicates the property to assign.
37+
/// - parameter object: The object that contains the property. The subscriber assigns the object's property every time it receives a new value.
38+
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically assign the property. Deinitializing this instance will also cancel automatic assignment.
39+
@_transparent public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root,Output>, onUnowned object: Root) -> AnyCancellable where Root:AnyObject {
40+
self.sink(receiveValue: { [unowned object] (value) in
41+
object[keyPath: keyPath] = value
42+
})
43+
}
4444
}
4545

4646
extension Publisher where Self.Failure==Never {
47-
/// Invoke on the given instance the specified method.
48-
/// - remark: A strong bond is set to `instance`. If you store the cancellable in the same instance as `instance`, a memory cycle will be created.
49-
/// - parameter method: A method/function metatype.
50-
/// - parameter instance: The instance defining the specified method.
51-
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically call the method. Deinitializing this instance will also cancel automatic invocation.
52-
@_transparent public func invoke<Root>(_ method: @escaping (Root)->(Output)->Void, on instance: Root) -> AnyCancellable {
53-
return self.sink(receiveValue: { (value) in
54-
method(instance)(value)
55-
})
56-
}
57-
58-
/// Invoke on the given instance the specified method.
59-
///
60-
/// The difference between `invoke(_:onWeak:)` and Combine's `invoke(_:on:)` is two-fold:
61-
/// - `invoke(_:onWeak:)` doesn't set a _strong bond_ to `object`.
62-
/// This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
63-
/// - `invoke(_:onWeak:)` cancels the upstream publisher if it detects `object` is deinitialized.
64-
///
65-
/// - parameter method: A method/function metatype.
66-
/// - parameter instance: The instance defining the specified method.
67-
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically call the method. Deinitializing this instance will also cancel automatic invocation.
68-
@_transparent public func invoke<Root>(_ method: @escaping (Root)->(Output)->Void, onWeak object: Root) -> AnyCancellable where Root:AnyObject {
69-
weak var cancellable: AnyCancellable? = nil
70-
let cleanup: (Subscribers.Completion<Never>) -> Void = { _ in
71-
cancellable?.cancel()
72-
cancellable = nil
73-
}
74-
75-
let subscriber = Subscribers.Sink<Output,Never>(receiveCompletion: cleanup, receiveValue: { [weak object] (value) in
76-
guard let object = object else { return cleanup(.finished) }
77-
method(object)(value)
78-
})
79-
80-
let result = AnyCancellable(subscriber)
81-
cancellable = result
82-
self.subscribe(subscriber)
83-
return result
84-
}
85-
86-
/// Invoke on the given instance the specified method.
87-
///
88-
/// The difference between `invoke(_:onUnowned:)` and Combine's `invoke(_:on:)` is that a _strong bond_ is not set to the`object`. This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
89-
/// - parameter method: A method/function metatype.
90-
/// - parameter instance: The instance defining the specified method.
91-
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically call the method. Deinitializing this instance will also cancel automatic invocation.
92-
@_transparent public func invoke<Root>(_ method: @escaping (Root)->(Output)->Void, onUnowned object: Root) -> AnyCancellable where Root:AnyObject {
93-
return self.sink(receiveValue: { [unowned object] (value) in
94-
method(object)(value)
95-
})
47+
/// Invoke on the given instance the specified method.
48+
/// - remark: A strong bond is set to `instance`. If you store the cancellable in the same instance as `instance`, a memory cycle will be created.
49+
/// - parameter method: A method/function metatype.
50+
/// - parameter instance: The instance defining the specified method.
51+
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically call the method. Deinitializing this instance will also cancel automatic invocation.
52+
@_transparent public func invoke<Root>(_ method: @escaping (Root)->(Output)->Void, on instance: Root) -> AnyCancellable {
53+
self.sink(receiveValue: { (value) in
54+
method(instance)(value)
55+
})
56+
}
57+
58+
/// Invoke on the given instance the specified method.
59+
///
60+
/// The difference between `invoke(_:onWeak:)` and Combine's `invoke(_:on:)` is two-fold:
61+
/// - `invoke(_:onWeak:)` doesn't set a _strong bond_ to `object`.
62+
/// This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
63+
/// - `invoke(_:onWeak:)` cancels the upstream publisher if it detects `object` is deinitialized.
64+
///
65+
/// - parameter method: A method/function metatype.
66+
/// - parameter instance: The instance defining the specified method.
67+
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically call the method. Deinitializing this instance will also cancel automatic invocation.
68+
@_transparent public func invoke<Root>(_ method: @escaping (Root)->(Output)->Void, onWeak object: Root) -> AnyCancellable where Root:AnyObject {
69+
weak var cancellable: AnyCancellable? = nil
70+
let cleanup: (Subscribers.Completion<Never>) -> Void = { _ in
71+
cancellable?.cancel()
72+
cancellable = nil
9673
}
74+
75+
let subscriber = Subscribers.Sink<Output,Never>(receiveCompletion: cleanup, receiveValue: { [weak object] (value) in
76+
guard let object = object else { return cleanup(.finished) }
77+
method(object)(value)
78+
})
79+
80+
let result = AnyCancellable(subscriber)
81+
cancellable = result
82+
self.subscribe(subscriber)
83+
return result
84+
}
85+
86+
/// Invoke on the given instance the specified method.
87+
///
88+
/// The difference between `invoke(_:onUnowned:)` and Combine's `invoke(_:on:)` is that a _strong bond_ is not set to the`object`. This breaks memory cycles when `object` also stores the returned cancellable (e.g. passing `self` is a common case).
89+
/// - parameter method: A method/function metatype.
90+
/// - parameter instance: The instance defining the specified method.
91+
/// - returns: An `AnyCancellable` instance. Call `cancel()` on the instance when you no longer want the publisher to automatically call the method. Deinitializing this instance will also cancel automatic invocation.
92+
@_transparent public func invoke<Root>(_ method: @escaping (Root)->(Output)->Void, onUnowned object: Root) -> AnyCancellable where Root:AnyObject {
93+
self.sink(receiveValue: { [unowned object] (value) in
94+
method(object)(value)
95+
})
96+
}
9797
}

sources/runtime/operators/AwaitOp.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ import Combine
22
import Foundation
33

44
extension Publisher {
5-
/// Subscribes to the receiving publichser and expects a single value and a subsequent successfull completion.
6-
///
7-
/// If no values is received, or more than one value is received, or a failure is received, the program will crash.
8-
/// - warning: The publisher must receive the value and completion event in a different queue from the queue where this property is called or the code will never execute.
9-
@inlinable public var await: Output {
10-
let group = DispatchGroup()
11-
group.enter()
12-
13-
var value: Output? = nil
14-
let cancellable = self.sink(fixedDemand: 1, receiveCompletion: {
15-
switch $0 {
16-
case .failure(let error): fatalError("\(error)")
17-
case .finished:
18-
guard case .some = value else { fatalError() }
19-
group.leave()
20-
}
21-
}, receiveValue: { value = $0 })
5+
/// Subscribes to the receiving publichser and expects a single value and a subsequent successfull completion.
6+
///
7+
/// If no values is received, or more than one value is received, or a failure is received, the program will crash.
8+
/// - warning: The publisher must receive the value and completion event in a different queue from the queue where this property is called or the code will never execute.
9+
@inlinable public var await: Output {
10+
let group = DispatchGroup()
11+
group.enter()
2212

23-
group.wait()
24-
cancellable.cancel()
25-
return value!
26-
}
13+
var value: Output? = nil
14+
let cancellable = self.sink(fixedDemand: 1, receiveCompletion: {
15+
switch $0 {
16+
case .failure(let error): fatalError("\(error)")
17+
case .finished:
18+
guard case .some = value else { fatalError() }
19+
group.leave()
20+
}
21+
}, receiveValue: { value = $0 })
22+
23+
group.wait()
24+
cancellable.cancel()
25+
return value!
26+
}
2727
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Combine
22

33
extension Publisher {
4-
/// Performs the specified closure when the publisher completes (whether successfully or with a failure) or when the publisher gets cancelled.
5-
///
6-
/// The closure will get executed exactly once.
7-
/// - parameter handle: A closure that executes when the publisher receives a completion event or when the publisher gets cancelled.
8-
/// - parameter completion: A completion event if the publisher completes (whether successfully or not), or `nil` in case the publisher is cancelled.
9-
@inlinable public func handleEnd(_ handle: @escaping (_ completion: Subscribers.Completion<Failure>?)->Void) -> Publishers.HandleEnd<Self> {
10-
.init(upstream: self, handle: handle)
11-
}
4+
/// Performs the specified closure when the publisher completes (whether successfully or with a failure) or when the publisher gets cancelled.
5+
///
6+
/// The closure will get executed exactly once.
7+
/// - parameter handle: A closure that executes when the publisher receives a completion event or when the publisher gets cancelled.
8+
/// - parameter completion: A completion event if the publisher completes (whether successfully or not), or `nil` in case the publisher is cancelled.
9+
@inlinable public func handleEnd(_ handle: @escaping (_ completion: Subscribers.Completion<Failure>?)->Void) -> Publishers.HandleEnd<Self> {
10+
.init(upstream: self, handle: handle)
11+
}
1212
}

0 commit comments

Comments
 (0)