@@ -38,47 +38,46 @@ extension TaskGroup {
38
38
let builtinSerialExecutor =
39
39
Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
40
40
41
- var task : Builtin . NativeObject ? =
42
- Builtin . createTask (
43
- flags: flags,
44
- initialSerialExecutor: builtinSerialExecutor,
45
- taskGroup: _group,
46
- operation: operation) . 0
47
-
48
- // Assert that we did create the task, but there's no need to store it,
49
- // as it was added to the group itself.
50
- assert ( task != nil , " Expected task to be created! " )
41
+
42
+ _ = Builtin . createTask (
43
+ flags: flags,
44
+ initialSerialExecutor: builtinSerialExecutor,
45
+ taskGroup: _group,
46
+ operation: operation) . 0
51
47
}
52
48
53
49
@available ( SwiftStdlib 5 . 1 , * )
54
50
@_alwaysEmitIntoClient
55
51
public mutating func addTaskUnlessCancelled(
56
52
priority: TaskPriority ? = nil ,
57
53
operation: sending @escaping @isolated ( any) ( ) async -> ChildTaskResult
58
- ) {
54
+ ) -> Bool {
55
+ let canAdd = _taskGroupAddPendingTask ( group: _group, unconditionally: false )
56
+
57
+ guard canAdd else {
58
+ return false
59
+ }
60
+
59
61
let flags = taskCreateFlags (
60
62
priority: priority,
61
63
isChildTask: true ,
62
64
copyTaskLocals: false ,
63
65
inheritContext: false ,
64
66
enqueueJob: true ,
65
67
addPendingGroupTaskUnconditionally: false ,
66
- isDiscardingTask: false
68
+ isDiscardingTask: true
67
69
)
68
70
69
71
let builtinSerialExecutor =
70
72
Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
71
73
72
- var task : Builtin . NativeObject ? =
73
- Builtin . createTask (
74
- flags: flags,
75
- initialSerialExecutor: builtinSerialExecutor,
76
- taskGroup: _group,
77
- operation: operation) . 0
74
+ _ = Builtin . createTask (
75
+ flags: flags,
76
+ initialSerialExecutor: builtinSerialExecutor,
77
+ taskGroup: _group,
78
+ operation: operation) . 0
78
79
79
- // Assert that we did create the task, but there's no need to store it,
80
- // as it was added to the group itself.
81
- assert ( task != nil , " Expected task to be created! " )
80
+ return true
82
81
}
83
82
}
84
83
@@ -104,47 +103,174 @@ extension ThrowingTaskGroup {
104
103
let builtinSerialExecutor =
105
104
Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
106
105
107
- var task : Builtin . NativeObject ? =
108
- Builtin . createTask (
109
- flags: flags,
110
- initialSerialExecutor: builtinSerialExecutor,
111
- taskGroup: _group,
112
- operation: operation) . 0
113
-
114
- // Assert that we did create the task, but there's no need to store it,
115
- // as it was added to the group itself.
116
- assert ( task != nil , " Expected task to be created! " )
106
+ _ = Builtin . createTask (
107
+ flags: flags,
108
+ initialSerialExecutor: builtinSerialExecutor,
109
+ taskGroup: _group,
110
+ operation: operation) . 0
117
111
}
118
112
119
113
@available ( SwiftStdlib 5 . 1 , * )
120
114
@_alwaysEmitIntoClient
121
115
public mutating func addTaskUnlessCancelled(
122
116
priority: TaskPriority ? = nil ,
123
117
operation: sending @escaping @isolated ( any) ( ) async throws -> ChildTaskResult
118
+ ) -> Bool {
119
+ let canAdd = _taskGroupAddPendingTask ( group: _group, unconditionally: false )
120
+
121
+ guard canAdd else {
122
+ return false
123
+ }
124
+
125
+ let flags = taskCreateFlags (
126
+ priority: priority,
127
+ isChildTask: true ,
128
+ copyTaskLocals: false ,
129
+ inheritContext: false ,
130
+ enqueueJob: true ,
131
+ addPendingGroupTaskUnconditionally: false ,
132
+ isDiscardingTask: true
133
+ )
134
+
135
+ let builtinSerialExecutor =
136
+ Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
137
+
138
+ _ = Builtin . createTask (
139
+ flags: flags,
140
+ initialSerialExecutor: builtinSerialExecutor,
141
+ taskGroup: _group,
142
+ operation: operation) . 0
143
+
144
+ return true
145
+ }
146
+ }
147
+
148
+ @available ( SwiftStdlib 5 . 9 , * )
149
+ extension DiscardingTaskGroup {
150
+
151
+ @available ( SwiftStdlib 5 . 9 , * )
152
+ @_alwaysEmitIntoClient
153
+ public mutating func addTask(
154
+ priority: TaskPriority ? = nil ,
155
+ operation: sending @escaping @isolated ( any) ( ) async -> Void
124
156
) {
157
+ let flags = taskCreateFlags (
158
+ priority: priority,
159
+ isChildTask: true ,
160
+ copyTaskLocals: false ,
161
+ inheritContext: false ,
162
+ enqueueJob: true ,
163
+ addPendingGroupTaskUnconditionally: true ,
164
+ isDiscardingTask: true
165
+ )
166
+
167
+ let builtinSerialExecutor =
168
+ Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
169
+
170
+ _ = Builtin . createTask (
171
+ flags: flags,
172
+ initialSerialExecutor: builtinSerialExecutor,
173
+ taskGroup: _group,
174
+ operation: operation) . 0
175
+ }
176
+
177
+ @available ( SwiftStdlib 5 . 9 , * )
178
+ @_alwaysEmitIntoClient
179
+ public mutating func addTaskUnlessCancelled(
180
+ priority: TaskPriority ? = nil ,
181
+ operation: sending @escaping @isolated ( any) ( ) async -> Void
182
+ ) -> Bool {
183
+ let canAdd = _taskGroupAddPendingTask ( group: _group, unconditionally: false )
184
+
185
+ guard canAdd else {
186
+ return false
187
+ }
188
+
125
189
let flags = taskCreateFlags (
126
190
priority: priority,
127
191
isChildTask: true ,
128
192
copyTaskLocals: false ,
129
193
inheritContext: false ,
130
194
enqueueJob: true ,
131
195
addPendingGroupTaskUnconditionally: false ,
132
- isDiscardingTask: false
196
+ isDiscardingTask: true
197
+ )
198
+
199
+ let builtinSerialExecutor =
200
+ Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
201
+
202
+ _ = Builtin . createTask (
203
+ flags: flags,
204
+ initialSerialExecutor: builtinSerialExecutor,
205
+ taskGroup: _group,
206
+ operation: operation) . 0
207
+
208
+ return true
209
+ }
210
+ }
211
+
212
+ @available ( SwiftStdlib 5 . 9 , * )
213
+ extension ThrowingDiscardingTaskGroup {
214
+
215
+ @available ( SwiftStdlib 5 . 9 , * )
216
+ @_alwaysEmitIntoClient
217
+ public mutating func addTask(
218
+ priority: TaskPriority ? = nil ,
219
+ operation: sending @escaping @isolated ( any) ( ) async throws -> Void
220
+ ) {
221
+ let flags = taskCreateFlags (
222
+ priority: priority,
223
+ isChildTask: true ,
224
+ copyTaskLocals: false ,
225
+ inheritContext: false ,
226
+ enqueueJob: true ,
227
+ addPendingGroupTaskUnconditionally: true ,
228
+ isDiscardingTask: true
229
+ )
230
+
231
+ let builtinSerialExecutor =
232
+ Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
233
+
234
+
235
+ _ = Builtin . createTask (
236
+ flags: flags,
237
+ initialSerialExecutor: builtinSerialExecutor,
238
+ taskGroup: _group,
239
+ operation: operation) . 0
240
+ }
241
+
242
+ @available ( SwiftStdlib 5 . 9 , * )
243
+ @_alwaysEmitIntoClient
244
+ public mutating func addTaskUnlessCancelled(
245
+ priority: TaskPriority ? = nil ,
246
+ operation: sending @escaping @isolated ( any) ( ) async throws -> Void
247
+ ) -> Bool {
248
+ let canAdd = _taskGroupAddPendingTask ( group: _group, unconditionally: false )
249
+
250
+ guard canAdd else {
251
+ return false
252
+ }
253
+
254
+ let flags = taskCreateFlags (
255
+ priority: priority,
256
+ isChildTask: true ,
257
+ copyTaskLocals: false ,
258
+ inheritContext: false ,
259
+ enqueueJob: true ,
260
+ addPendingGroupTaskUnconditionally: false ,
261
+ isDiscardingTask: true
133
262
)
134
263
135
264
let builtinSerialExecutor =
136
265
Builtin . extractFunctionIsolation ( operation) ? . unownedExecutor. executor
137
266
138
- var task : Builtin . NativeObject ? =
139
- Builtin . createTask (
140
- flags: flags,
141
- initialSerialExecutor: builtinSerialExecutor,
142
- taskGroup: _group,
143
- operation: operation) . 0
267
+ _ = Builtin . createTask (
268
+ flags: flags,
269
+ initialSerialExecutor: builtinSerialExecutor,
270
+ taskGroup: _group,
271
+ operation: operation) . 0
144
272
145
- // Assert that we did create the task, but there's no need to store it,
146
- // as it was added to the group itself.
147
- assert ( task != nil , " Expected task to be created! " )
273
+ return true
148
274
}
149
275
}
150
276
0 commit comments