Skip to content

Commit f3065c3

Browse files
authored
Merge pull request swiftlang#2488 from x4snowman/operation_add_dependency
2 parents 60ae6e8 + 0e8ba42 commit f3065c3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Foundation/Operation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ open class Operation : NSObject {
407407
withExtendedLifetime(op) {
408408
var up: Operation?
409409
_lock()
410-
if __dependencies.first(where: { $0 === op }) != nil {
410+
if __dependencies.first(where: { $0 === op }) == nil {
411411
__dependencies.append(op)
412412
up = op
413413
}

TestFoundation/TestOperationQueue.swift

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class TestOperationQueue : XCTestCase {
2525
("test_CurrentQueueWithCustomUnderlyingQueue", test_CurrentQueueWithCustomUnderlyingQueue),
2626
("test_CurrentQueueWithUnderlyingQueueResetToNil", test_CurrentQueueWithUnderlyingQueueResetToNil),
2727
("test_isSuspended", test_isSuspended),
28+
("test_OperationDependencyCount", test_OperationDependencyCount),
2829
]
2930
}
3031

@@ -264,6 +265,20 @@ class TestOperationQueue : XCTestCase {
264265

265266
waitForExpectations(timeout: 1)
266267
}
268+
269+
func test_OperationDependencyCount() {
270+
var results = [Int]()
271+
let op1 = BlockOperation {
272+
results.append(1)
273+
}
274+
op1.name = "op1"
275+
let op2 = BlockOperation {
276+
results.append(2)
277+
}
278+
op2.name = "op2"
279+
op1.addDependency(op2)
280+
XCTAssert(op1.dependencies.count == 1)
281+
}
267282
}
268283

269284
class AsyncOperation: Operation {

0 commit comments

Comments
 (0)