File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -407,7 +407,7 @@ open class Operation : NSObject {
407
407
withExtendedLifetime ( op) {
408
408
var up : Operation ?
409
409
_lock ( )
410
- if __dependencies. first ( where: { $0 === op } ) ! = nil {
410
+ if __dependencies. first ( where: { $0 === op } ) = = nil {
411
411
__dependencies. append ( op)
412
412
up = op
413
413
}
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class TestOperationQueue : XCTestCase {
25
25
( " test_CurrentQueueWithCustomUnderlyingQueue " , test_CurrentQueueWithCustomUnderlyingQueue) ,
26
26
( " test_CurrentQueueWithUnderlyingQueueResetToNil " , test_CurrentQueueWithUnderlyingQueueResetToNil) ,
27
27
( " test_isSuspended " , test_isSuspended) ,
28
+ ( " test_OperationDependencies " , test_OperationDependencies) ,
28
29
]
29
30
}
30
31
@@ -264,6 +265,26 @@ class TestOperationQueue : XCTestCase {
264
265
265
266
waitForExpectations ( timeout: 1 )
266
267
}
268
+
269
+ func test_OperationDependencies( ) {
270
+ let queue = OperationQueue ( )
271
+ var results = [ Int] ( )
272
+ queue. maxConcurrentOperationCount = 1
273
+ let op1 = BlockOperation {
274
+ results. append ( 1 )
275
+ }
276
+ op1. name = " op1 "
277
+ let op2 = BlockOperation {
278
+ results. append ( 2 )
279
+ }
280
+ op2. name = " op2 "
281
+ op1. addDependency ( op2)
282
+ XCTAssert ( op1. dependencies. count == 1 )
283
+ queue. addOperation ( op1)
284
+ queue. addOperation ( op2)
285
+ queue. waitUntilAllOperationsAreFinished ( )
286
+ XCTAssertEqual ( results, [ 2 , 1 ] )
287
+ }
267
288
}
268
289
269
290
class AsyncOperation : Operation {
You can’t perform that action at this time.
0 commit comments