Skip to content

Commit 807678a

Browse files
mbvreddyparkera
authored andcommitted
fix NSOperationQueue to retain operation in 'all' queue once it is dispatched (#344)
1 parent c8645bd commit 807678a

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Foundation/NSOperation.swift

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,22 @@ internal struct _OperationList {
258258
}
259259

260260
mutating func dequeue() -> NSOperation? {
261-
var result : NSOperation?
262261
if veryHigh.count > 0 {
263-
result = veryHigh.remove(at: 0)
264-
} else if high.count > 0 {
265-
result = high.remove(at: 0)
266-
} else if normal.count > 0 {
267-
result = normal.remove(at: 0)
268-
} else if low.count > 0 {
269-
result = low.remove(at: 0)
270-
} else if veryLow.count > 0 {
271-
result = veryLow.remove(at: 0)
262+
return veryHigh.remove(at: 0)
272263
}
273-
274-
if let idx = all.index(of: result!) {
275-
all.remove(at: idx)
264+
if high.count > 0 {
265+
return high.remove(at: 0)
276266
}
277-
278-
return result
267+
if normal.count > 0 {
268+
return normal.remove(at: 0)
269+
}
270+
if low.count > 0 {
271+
return low.remove(at: 0)
272+
}
273+
if veryLow.count > 0 {
274+
return veryLow.remove(at: 0)
275+
}
276+
return nil
279277
}
280278

281279
var count: Int {

0 commit comments

Comments
 (0)