title: How can I use DispatchSemaphore with a Closure
body: <p>I have a value that looks like this</p>
  
  <pre><code>   lazy var authHeaders: [String: String] = {
          if shouldTokenBeRefreshed() {
              let semaphore = DispatchSemaphore(value: 0)
              refreshTokens {
                  semaphore.signal()
              }
              semaphore.wait()
          }
          return ["Authorization": "Bearer \(module.client.credential.oauthToken)"]
      }()
  </code></pre>
  
  <p>The idea is, when requesting my <code>auth headers</code>, if my token has expired I will refresh it and then return the new value instead.</p>
  
  <pre><code>func refreshTokens(completion: @escaping () -&gt; Void) {
      guard let token = keychain.get("refresh_token") else { return }
  
      module.renewAccessToken(
          withRefreshToken: token,
          success: { [weak self] credential, response, parameters in
              guard let self = self else { return }
              self.storeTokens([
                  "access_token": credential.oauthToken,
                  "refresh_token": credential.oauthRefreshToken
              ])
              completion()
          },
          failure: { error in
              print(error.description)
          })
  }
  </code></pre>
  
  <p>As this is an <code>async</code> operation, I have tried to pause the flow using a <code>Semaphore</code> so I can cause it to continue once the completion block is triggered.</p>
  
  <p>The call is not resolving however and I am unsure why.</p>