File tree 2 files changed +21
-11
lines changed
2 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -668,22 +668,16 @@ open class BlockOperation : Operation {
668
668
}
669
669
_lock ( )
670
670
defer { _unlock ( ) }
671
- if _block == nil && _executionBlocks == nil {
671
+ if _block == nil {
672
672
_block = block
673
+ } else if _executionBlocks == nil {
674
+ _executionBlocks = [ block]
673
675
} else {
674
- if _executionBlocks == nil {
675
- if let existing = _block {
676
- _executionBlocks = [ existing, block]
677
- } else {
678
- _executionBlocks = [ block]
679
- }
680
- } else {
681
- _executionBlocks? . append ( block)
682
- }
676
+ _executionBlocks? . append ( block)
683
677
}
684
678
}
685
679
686
- open var executionBlocks : [ @ convention ( block ) ( ) -> Void ] {
680
+ open var executionBlocks : [ ( ) -> Void ] {
687
681
get {
688
682
_lock ( )
689
683
defer { _unlock ( ) }
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class TestOperationQueue : XCTestCase {
42
42
( " test_Lifecycle " , test_Lifecycle) ,
43
43
( " test_ConcurrentOperations " , test_ConcurrentOperations) ,
44
44
( " test_ConcurrentOperationsWithDependenciesAndCompletions " , test_ConcurrentOperationsWithDependenciesAndCompletions) ,
45
+ ( " test_BlockOperationAddExecutionBlock " , test_BlockOperationAddExecutionBlock) ,
45
46
]
46
47
}
47
48
@@ -753,6 +754,21 @@ class TestOperationQueue : XCTestCase {
753
754
}
754
755
}
755
756
757
+ func test_BlockOperationAddExecutionBlock( ) {
758
+ let block1Expectation = expectation ( description: " Block 1 executed " )
759
+ let block2Expectation = expectation ( description: " Block 2 executed " )
760
+
761
+ let blockOperation = BlockOperation {
762
+ block1Expectation. fulfill ( )
763
+ }
764
+ blockOperation. addExecutionBlock {
765
+ block2Expectation. fulfill ( )
766
+ }
767
+ XCTAssert ( blockOperation. executionBlocks. count == 2 )
768
+ let queue = OperationQueue ( )
769
+ queue. addOperation ( blockOperation)
770
+ waitForExpectations ( timeout: 1.0 )
771
+ }
756
772
}
757
773
758
774
class AsyncOperation : Operation {
You can’t perform that action at this time.
0 commit comments