Skip to content

Commit a640a70

Browse files
committed
Working publishers
1 parent fe510c8 commit a640a70

File tree

6 files changed

+856
-6
lines changed

6 files changed

+856
-6
lines changed

Sources/ParseSwift/Objects/ParseInstallation+combine.swift

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public extension ParseInstallation {
3232

3333
// MARK: Savable - Combine
3434
/**
35-
Saves the `ParseInstallation` *asynchronously* and executes the given callback block.
35+
Saves the `ParseInstallation` *asynchronously* and publishes when complete.
3636

3737
- parameter options: A set of header options sent to the server. Defaults to an empty set.
3838
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -47,7 +47,7 @@ public extension ParseInstallation {
4747

4848
// MARK: Deletable - Combine
4949
/**
50-
Deletes the `ParseInstallation` *asynchronously* and executes the given callback block.
50+
Deletes the `ParseInstallation` *asynchronously* and publishes when complete.
5151

5252
- parameter options: A set of header options sent to the server. Defaults to an empty set.
5353
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -60,4 +60,50 @@ public extension ParseInstallation {
6060
}
6161
}
6262

63+
// MARK: Batch Support - Combine
64+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
65+
public extension Sequence where Element: ParseInstallation {
66+
/**
67+
Fetches a collection of installations *aynchronously* with the current data from the server and sets
68+
an error if one occurs. Publishes when complete.
69+
70+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
71+
- returns: A publisher that eventually produces a single value and then finishes or fails.
72+
- important: If an object fetched has the same objectId as current, it will automatically update the current.
73+
*/
74+
func fetchAllPublisher(options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
75+
Future { promise in
76+
fetchAll(options: options,
77+
completion: promise)
78+
}
79+
}
80+
81+
/**
82+
Saves a collection of installations *asynchronously* and publishes when complete.
83+
84+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
85+
- returns: A publisher that eventually produces a single value and then finishes or fails.
86+
- important: If an object saved has the same objectId as current, it will automatically update the current.
87+
*/
88+
func saveAllPublisher(options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
89+
Future { promise in
90+
saveAll(options: options,
91+
completion: promise)
92+
}
93+
}
94+
95+
/**
96+
Deletes a collection of installations *asynchronously* and and publishes when complete.
97+
98+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
99+
- returns: A publisher that eventually produces a single value and then finishes or fails.
100+
- important: If an object deleted has the same objectId as current, it will automatically update the current.
101+
*/
102+
func deleteAllPublisher(options: API.Options = []) -> Future<[(Result<Void, ParseError>)], ParseError> {
103+
Future { promise in
104+
deleteAll(options: options, completion: promise)
105+
}
106+
}
107+
}
108+
63109
#endif

Sources/ParseSwift/Objects/ParseObject+combine.swift

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public extension ParseObject {
3030
}
3131

3232
/**
33-
Saves the `ParseObject` *asynchronously* and executes the given callback block.
33+
Saves the `ParseObject` *asynchronously* and publishes when complete.
3434

3535
- parameter options: A set of header options sent to the server. Defaults to an empty set.
3636
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -44,7 +44,7 @@ public extension ParseObject {
4444
}
4545

4646
/**
47-
Deletes the `ParseObject` *asynchronously* and executes the given callback block.
47+
Deletes the `ParseObject` *asynchronously* and publishes when complete.
4848

4949
- parameter options: A set of header options sent to the server. Defaults to an empty set.
5050
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -57,4 +57,50 @@ public extension ParseObject {
5757
}
5858
}
5959

60+
// MARK: Batch Support - Combine
61+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
62+
public extension Sequence where Element: ParseObject {
63+
/**
64+
Fetches a collection of objects *aynchronously* with the current data from the server and sets
65+
an error if one occurs. Publishes when complete.
66+
67+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
68+
- returns: A publisher that eventually produces a single value and then finishes or fails.
69+
- important: If an object fetched has the same objectId as current, it will automatically update the current.
70+
*/
71+
func fetchAllPublisher(options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
72+
Future { promise in
73+
fetchAll(options: options,
74+
completion: promise)
75+
}
76+
}
77+
78+
/**
79+
Saves a collection of objects *asynchronously* and publishes when complete.
80+
81+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
82+
- returns: A publisher that eventually produces a single value and then finishes or fails.
83+
- important: If an object saved has the same objectId as current, it will automatically update the current.
84+
*/
85+
func saveAllPublisher(options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
86+
Future { promise in
87+
saveAll(options: options,
88+
completion: promise)
89+
}
90+
}
91+
92+
/**
93+
Deletes a collection of objects *asynchronously* and and publishes when complete.
94+
95+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
96+
- returns: A publisher that eventually produces a single value and then finishes or fails.
97+
- important: If an object deleted has the same objectId as current, it will automatically update the current.
98+
*/
99+
func deleteAllPublisher(options: API.Options = []) -> Future<[(Result<Void, ParseError>)], ParseError> {
100+
Future { promise in
101+
deleteAll(options: options, completion: promise)
102+
}
103+
}
104+
}
105+
60106
#endif

Sources/ParseSwift/Objects/ParseUser+combine.swift

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public extension ParseUser {
153153

154154
// MARK: Savable - Combine
155155
/**
156-
Saves the `ParseUser` *asynchronously* and executes the given callback block.
156+
Saves the `ParseUser` *asynchronously* and publishes when complete.
157157

158158
- parameter options: A set of header options sent to the server. Defaults to an empty set.
159159
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -168,7 +168,7 @@ public extension ParseUser {
168168

169169
// MARK: Deletable - Combine
170170
/**
171-
Deletes the `ParseUser` *asynchronously* and executes the given callback block.
171+
Deletes the `ParseUser` *asynchronously* and publishes when complete.
172172

173173
- parameter options: A set of header options sent to the server. Defaults to an empty set.
174174
- returns: A publisher that eventually produces a single value and then finishes or fails.
@@ -181,4 +181,49 @@ public extension ParseUser {
181181
}
182182
}
183183

184+
// MARK: Batch Support - Combine
185+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
186+
public extension Sequence where Element: ParseUser {
187+
/**
188+
Fetches a collection of users *aynchronously* with the current data from the server and sets
189+
an error if one occurs. Publishes when complete.
190+
191+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
192+
- returns: A publisher that eventually produces a single value and then finishes or fails.
193+
- important: If an object fetched has the same objectId as current, it will automatically update the current.
194+
*/
195+
func fetchAllPublisher(options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
196+
Future { promise in
197+
fetchAll(options: options,
198+
completion: promise)
199+
}
200+
}
201+
202+
/**
203+
Saves a collection of users *asynchronously* and publishes when complete.
204+
205+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
206+
- returns: A publisher that eventually produces a single value and then finishes or fails.
207+
- important: If an object saved has the same objectId as current, it will automatically update the current.
208+
*/
209+
func saveAllPublisher(options: API.Options = []) -> Future<[(Result<Self.Element, ParseError>)], ParseError> {
210+
Future { promise in
211+
saveAll(options: options,
212+
completion: promise)
213+
}
214+
}
215+
216+
/**
217+
Deletes a collection of users *asynchronously* and and publishes when complete.
218+
219+
- parameter options: A set of header options sent to the server. Defaults to an empty set.
220+
- returns: A publisher that eventually produces a single value and then finishes or fails.
221+
- important: If an object deleted has the same objectId as current, it will automatically update the current.
222+
*/
223+
func deleteAllPublisher(options: API.Options = []) -> Future<[(Result<Void, ParseError>)], ParseError> {
224+
Future { promise in
225+
deleteAll(options: options, completion: promise)
226+
}
227+
}
228+
}
184229
#endif

0 commit comments

Comments
 (0)