I'm trying to return a boolean to a delegate of an SDK, but I need my function to wait for the callback of another function. I think it becomes clear what I want to do with the code below:

func conversation(_ conversation: SKTConversation, shouldShowInAppNotificationFor message: SKTMessage) -> Bool {

    NSLog("shouldShow0")
    let semaphore = DispatchSemaphore(value: 0)

    // Default = true
    var shouldShow: Bool = true

    self.channel?.invokeMethod("shouldShow", arguments: nil, result: { result in

      NSLog("invokeMethod result: \(String(describing: result))")

      if let result = result as? FlutterError {
        NSLog("Flutter Error! Message: \(result.message) | Description: \(result.description)")
      }

      guard let result = result as? NSNumber else {
        NSLog("inside !NSNumber")
        semaphore.signal()
        return
      }

      NSLog("inside NSNumber")
      // I need to return this result:
      shouldShow = result.boolValue
      semaphore.signal()
    })

    NSLog("shouldShow1")
    semaphore.wait()
    NSLog("shouldShow2")

    return shouldShow
  }

The problem is that my application is breaking when calling semaphore.wait() since I can't get a callback when this is called. These are my logs:

shouldShow0
shouldShow1
flutter: reached here!
flutter: returning true!

I'm returning the value in flutter but the callback is not being called because of the semaphore.wait() Obs: If I comment the semaphore.wait(), the callback works!

Sorry if it's a newbie question, I'm a Flutter developer and I'm getting into the native world