-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathParseInstallation+async.swift
155 lines (145 loc) · 7.64 KB
/
ParseInstallation+async.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
// ParseInstallation+async.swift
// ParseInstallation+async
//
// Created by Corey Baker on 8/6/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if swift(>=5.5) && canImport(_Concurrency)
import Foundation
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
public extension ParseInstallation {
// MARK: Fetchable - Async/Await
/**
Fetches the `ParseInstallation` *aynchronously* with the current data from the server
and sets an error if one occurs. Publishes when complete.
- parameter includeKeys: The name(s) of the key(s) to include that are
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
`includeAll` for `Query`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: Returns saved `ParseInstallation`.
- throws: `ParseError`.
- important: If an object fetched has the same objectId as current, it will automatically update the current.
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
desires a different policy, it should be inserted in `options`.
*/
func fetch(includeKeys: [String]? = nil,
options: API.Options = []) async throws -> Self {
try await withCheckedThrowingContinuation { continuation in
self.fetch(includeKeys: includeKeys,
options: options,
completion: continuation.resume)
}
}
// MARK: Savable - Async/Await
/**
Saves the `ParseInstallation` *asynchronously*.
- parameter isIgnoreCustomObjectIdConfig: Ignore checking for `objectId`
when `ParseConfiguration.allowCustomObjectId = true` to allow for mixed
`objectId` environments. Defaults to false.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: Returns saved `ParseInstallation`.
- throws: `ParseError`.
- important: If an object saved has the same objectId as current, it will automatically update the current.
*/
func save(isIgnoreCustomObjectIdConfig: Bool = false,
options: API.Options = []) async throws -> Self {
try await withCheckedThrowingContinuation { continuation in
self.save(isIgnoreCustomObjectIdConfig: isIgnoreCustomObjectIdConfig,
options: options,
completion: continuation.resume)
}
}
// MARK: Deletable - Async/Await
/**
Deletes the `ParseInstallation` *asynchronously*.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: Returns saved `ParseInstallation`.
- throws: `ParseError`.
- important: If an object deleted has the same objectId as current, it will automatically update the current.
*/
func delete(options: API.Options = []) async throws {
_ = try await withCheckedThrowingContinuation { continuation in
self.delete(options: options, completion: continuation.resume)
}
}
}
// MARK: Batch Support - Async/Await
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
public extension Sequence where Element: ParseInstallation {
/**
Fetches a collection of installations *aynchronously* with the current data from the server and sets
an error if one occurs.
- parameter includeKeys: The name(s) of the key(s) to include that are
`ParseObject`s. Use `["*"]` to include all keys. This is similar to `include` and
`includeAll` for `Query`.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: Returns saved `ParseInstallation`.
- throws: `ParseError`.
- important: If an object fetched has the same objectId as current, it will automatically update the current.
*/
func fetchAll(includeKeys: [String]? = nil,
options: API.Options = []) async throws -> [(Result<Self.Element, ParseError>)] {
try await withCheckedThrowingContinuation { continuation in
self.fetchAll(includeKeys: includeKeys,
options: options,
completion: continuation.resume)
}
}
/**
Saves a collection of installations *asynchronously*.
- parameter batchLimit: The maximum number of objects to send in each batch. If the items to be batched.
is greater than the `batchLimit`, the objects will be sent to the server in waves up to the `batchLimit`.
Defaults to 50.
- parameter transaction: Treat as an all-or-nothing operation. If some operation failure occurs that
prevents the transaction from completing, then none of the objects are committed to the Parse Server database.
- parameter isIgnoreCustomObjectIdConfig: Ignore checking for `objectId`
when `ParseConfiguration.allowCustomObjectId = true` to allow for mixed
`objectId` environments. Defaults to false.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: - returns: Returns saved `ParseInstallation`.
- throws: `ParseError`.
- important: If an object saved has the same objectId as current, it will automatically update the current.
- warning: If `transaction = true`, then `batchLimit` will be automatically be set to the amount of the
objects in the transaction. The developer should ensure their respective Parse Servers can handle the limit or else
the transactions can fail.
*/
func saveAll(batchLimit limit: Int? = nil,
transaction: Bool = false,
isIgnoreCustomObjectIdConfig: Bool = false,
options: API.Options = []) async throws -> [(Result<Self.Element, ParseError>)] {
try await withCheckedThrowingContinuation { continuation in
self.saveAll(batchLimit: limit,
transaction: transaction,
isIgnoreCustomObjectIdConfig: isIgnoreCustomObjectIdConfig,
options: options,
completion: continuation.resume)
}
}
/**
Deletes a collection of installations *asynchronously*.
- parameter batchLimit: The maximum number of objects to send in each batch. If the items to be batched.
is greater than the `batchLimit`, the objects will be sent to the server in waves up to the `batchLimit`.
Defaults to 50.
- parameter transaction: Treat as an all-or-nothing operation. If some operation failure occurs that
prevents the transaction from completing, then none of the objects are committed to the Parse Server database.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: Returns saved `ParseInstallation`.
- throws: `ParseError`.
- important: If an object deleted has the same objectId as current, it will automatically update the current.
- warning: If `transaction = true`, then `batchLimit` will be automatically be set to the amount of the
objects in the transaction. The developer should ensure their respective Parse Servers can handle the limit or else
the transactions can fail.
*/
func deleteAll(batchLimit limit: Int? = nil,
transaction: Bool = false,
options: API.Options = []) async throws -> [(Result<Void, ParseError>)] {
try await withCheckedThrowingContinuation { continuation in
self.deleteAll(batchLimit: limit,
transaction: transaction,
options: options,
completion: continuation.resume)
}
}
}
#endif