title: swift - why not working my semaphore?
body: <pre><code>class BLEManager {
      private let bleManagerCB = BLEManagerCB()
  
      func checkPowered() -&gt; Bool {
          let semaphore = DispatchSemaphore(value: 0)
          var state : Bool?
  
          bleManagerCB.checkPowered()
          bleManagerCB.onCompletionPowered = { result in
              state = result
              self.semaphore.signal()
          }
          semaphore.wait()
          return state
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>class BLEManagerCB:NSObject, CBCentralManagerDelegate {
  
      var centralManager:CBCentralManager!
      var onCompletionPowered:((_ result:Bool) -&gt; Void)?
  
      func checkPowered() {
          centralManager = CBCentralManager(delegate: self, queue: nil)
          //centralManagerDidUpdateState(delegate method) call.
      }
  
      //check power
      func centralManagerDidUpdateState(_ central: CBCentralManager) {
          if central.state == .poweredOn {
              onCompletionPowered!(true)
  
          } else if central.state == .poweredOff {
              onCompletionPowered!(false)
          }
      }
  }
  </code></pre>
  
  <p>hi, i have a question for semaphore. look at my code please.
  why my semaphore is not working?
  it's matter of closure code?
  i want to 'checkPowered function' is synchronous active.  </p>