Skip to content

why does the Swift code generated by Postman use semaphores? #10053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mattneub opened this issue Jun 21, 2021 · 3 comments
Closed

why does the Swift code generated by Postman use semaphores? #10053

mattneub opened this issue Jun 21, 2021 · 3 comments

Comments

@mattneub
Copy link

mattneub commented Jun 21, 2021

Start with a simple GET request in Postman, and then ask Postman to generate the code for the corresponding Swift equivalent using URLSession. You'll get something with this form:

var semaphore = DispatchSemaphore (value: 0)
var request = //
let task = URLSession.shared.dataTask(with: request) { data, response, error in 
  guard let data = data else {
    print(String(describing: error))
    semaphore.signal()
    return
  }
  print(String(data: data, encoding: .utf8)!)
  semaphore.signal()
}
task.resume()
semaphore.wait()

This is wrong. One should basically never use semaphores, and certainly there is no need for them here. The correct answer to the question that we're asking Postman, how to perform this same request in Swift, is to take all of that code and delete every line containing the word "semaphore". So, since everyone is always going to have to do that, why include those lines to begin with?

@akshaydeo
Copy link

@mattneub Thank you for reporting this issue. We are working on the fix and will release the fix by the end of Jan 2023

@SahilChoudhary22
Copy link

@mattneub Thanks again for the input!
We've raised a PR regarding the removal of the unnecessary semaphores and it's currently under review. It should be live with the next release of the module and you should be able to observe the change in the next release of Postman app. 👍 Stay tuned!

@arlemi
Copy link
Collaborator

arlemi commented Feb 16, 2023

Fixed in Postman v10.10. Let us know if you're still having issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants