Search code examples
apiblocking

Is having a function call block a bad design process?


I'm writing an API which is used to receive some data from another application. Currently the function is designed to block until data is received. In my mind this limits developers using the API to use multithreading or some sort of multi-process design. So is it better for a function to block or to return a null and then sleep for a few milliseconds before trying again.

Note the other application may not have any data to send through the API for an unknown period of time.

The API is written in C++


Solution

  • Why not use a callback?