Support Topics Documentation Slack YouTube Blog

Backendless API does not block until call to response handler

The Backendless 5.0 APIs don’t seem to block until the call returns. Instead, they seem to step over to the next line after the closure, here’s an example.

I currently use the login API to login the user and then restore the user info from the Backendless server in the response handler. However, the login call doesn’t block until the response handler is called. Instead, it steps right over, only for the handler to be called later.

That behavior seems like what an asynchronous call would, maybe I am missing something or doing it incorrectly.

I am using Swift 4.2 and on Backendless 5.x btw.

Can someone please clarify? Thanks!

Here is the code snippet:

func loginUser(mobileNumber: String, passcode:String) -> Bool {
         var success = true
   
        let backendless = Backendless.shared
        backendless.userService.login(identity: mobileNumber, password: passcode, responseHandler: {user in
   // CODE TO HANDLE SUCCESSFUL LOGIN GOES HERE
}, errorHandler: {fault in
   // ERROR HANDLING CODE HERE
  success  = false
})

return success
}

Hello,

Swift-SDK provides the asynchronous (non-blocking) methods. You can use Future or semaphores or some other third-party framework/library that best suits your needs.

Regards,
Olha

Thanks Olha, I re-read that documentation and realized what you said :slight_smile: ! However, the text in the doc page is somewhat misleading. It says “Blocking and Non-Blocking APIs” while the Swift version only seems to offer async or non-blocking APIs that use closures (or blocks) where server responses are returned. But that’s not the same thing as blocking (or synchronous) as I understand it.

Is there a synchronous API that I can use or there is none?

Thanks for your help, truly appreciate it.

Yes, there is no synchronous API in Swift-SDK. And

You can use Future or semaphores or some other third-party framework/library that best suits your needs.

I mean you can wrap your async code manually to make it synchronous, but Swift-SDK doesn’t provide synchronous API.

Regards,
Olha

Thank you for confirming, appreciate it.