Skip to content

Commit f2dbd65

Browse files
authored
Merge pull request #10713 from ktopley-apple/dispatch-sync-fixup
Fix warnings in DispatchQueue.sync() implementation when using a comp…
2 parents 3ccc69a + 6194f37 commit f2dbd65

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

stdlib/public/SDK/Dispatch/Queue.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,13 @@ public extension DispatchQueue {
232232
{
233233
var result: T?
234234
var error: Error?
235-
fn {
236-
do {
237-
result = try work()
238-
} catch let e {
239-
error = e
235+
withoutActuallyEscaping(work) { _work in
236+
fn {
237+
do {
238+
result = try _work()
239+
} catch let e {
240+
error = e
241+
}
240242
}
241243
}
242244
if let e = error {

test/stdlib/Dispatch.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ DispatchAPI.test("DispatchGroup creation") {
4040
expectNotNil(group)
4141
}
4242

43+
DispatchAPI.test("Dispatch sync return value") {
44+
let value = 24;
45+
let q = DispatchQueue(label: "Test")
46+
let result = q.sync() { return 24 }
47+
expectEqual(value, result)
48+
}
49+
4350
DispatchAPI.test("dispatch_block_t conversions") {
4451
var counter = 0
4552
let closure = { () -> Void in

0 commit comments

Comments
 (0)