File tree Expand file tree Collapse file tree 3 files changed +50
-6
lines changed Expand file tree Collapse file tree 3 files changed +50
-6
lines changed Original file line number Diff line number Diff line change @@ -204,6 +204,7 @@ internal struct _OperationList {
204
204
var all = [ NSOperation] ( )
205
205
206
206
mutating func insert( _ operation: NSOperation ) {
207
+ all. append ( operation)
207
208
switch operation. queuePriority {
208
209
case . VeryLow:
209
210
veryLow. append ( operation)
@@ -257,22 +258,28 @@ internal struct _OperationList {
257
258
}
258
259
259
260
mutating func dequeue( ) -> NSOperation ? {
261
+ var result : NSOperation ?
260
262
if veryHigh. count > 0 {
261
- return veryHigh. remove ( at: 0 )
263
+ result = veryHigh. remove ( at: 0 )
262
264
}
263
265
if high. count > 0 {
264
- return high. remove ( at: 0 )
266
+ result = high. remove ( at: 0 )
265
267
}
266
268
if normal. count > 0 {
267
- return normal. remove ( at: 0 )
269
+ result = normal. remove ( at: 0 )
268
270
}
269
271
if low. count > 0 {
270
- return low. remove ( at: 0 )
272
+ result = low. remove ( at: 0 )
271
273
}
272
274
if veryLow. count > 0 {
273
- return veryLow. remove ( at: 0 )
275
+ result = veryLow. remove ( at: 0 )
274
276
}
275
- return nil
277
+
278
+ if let idx = all. index ( of: result!) {
279
+ all. remove ( at: idx)
280
+ }
281
+
282
+ return result
276
283
}
277
284
278
285
var count : Int {
Original file line number Diff line number Diff line change
1
+ // This source file is part of the Swift.org open source project
2
+ //
3
+ // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
4
+ // Licensed under Apache License v2.0 with Runtime Library Exception
5
+ //
6
+ // See http://swift.org/LICENSE.txt for license information
7
+ // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8
+ //
9
+
10
+
11
+
12
+ #if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
13
+ import Foundation
14
+ import XCTest
15
+ #else
16
+ import SwiftFoundation
17
+ import SwiftXCTest
18
+ #endif
19
+
20
+ class TestNSOperationQueue : XCTestCase {
21
+ static var allTests : [ ( String , TestNSOperationQueue -> ( ) throws -> Void ) ] {
22
+ return [
23
+ ( " test_OperationCount " , test_OperationCount)
24
+ ]
25
+ }
26
+
27
+ func test_OperationCount( ) {
28
+ let queue = NSOperationQueue ( )
29
+ let op1 = NSBlockOperation ( block: { sleep ( 2 ) } )
30
+ queue. addOperation ( op1)
31
+ XCTAssertTrue ( queue. operationCount == 1 )
32
+ /* uncomment below lines once Dispatch is enabled in Foundation */
33
+ //queue.waitUntilAllOperationsAreFinished()
34
+ //XCTAssertTrue(queue.operationCount == 0)
35
+ }
36
+ }
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ XCTMain([
46
46
testCase ( TestNSNull . allTests) ,
47
47
testCase ( TestNSNumber . allTests) ,
48
48
testCase ( TestNSNumberFormatter . allTests) ,
49
+ testCase ( TestNSOperationQueue . allTests) ,
49
50
testCase ( TestNSOrderedSet . allTests) ,
50
51
testCase ( TestNSPipe . allTests) ,
51
52
testCase ( TestNSPredicate . allTests) ,
You can’t perform that action at this time.
0 commit comments