Last active
          February 14, 2019 14:53 
        
      - 
      
- 
        Save sisoje/ae9eef2294ecb2e312448c5813730de0 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | extension XCTestExpectation { | |
| var fulfiller: DeinitBlock { | |
| return DeinitBlock { | |
| print("Fulfill \(self.description)") | |
| self.fulfill() | |
| } | |
| } | |
| } | |
| class FillfilerTests: XCTestCase { | |
| func testFulfillWithDispatchQueue() { | |
| let queue = DispatchQueue(label: #function) | |
| (0..<10).forEach { index in | |
| let fulfiller = expectation(description: "\(#function) \(index)").fulfiller | |
| if index.isMultiple(of: 2) { | |
| // automatically fulfilled on exiting scope | |
| return | |
| } | |
| queue.async { | |
| // fullfiled when closure is released | |
| print("Retaining: \(fulfiller)") | |
| } | |
| } | |
| waitForExpectations(timeout: 1, handler: nil) | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment