cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: async usage in examples

async usage in examples

Tzach K.
New member | Level 1

I have a question regarding the API v2 examples as a whole. All of the examples supplies use async calls. even for login. However you use task.wait() after the Task creation which essentially makes the call synchronous as the program waits for the task to complete. 

You use async threads if those threads do operations  that are independent of the main path or other threads(not including sharing information from those threads). What is the idea behind using it to perform login and task.wait()?

5 Replies 5

Greg-DB
Dropbox Staff

Are you asking why the decision was made to use task.wait() in that case? I can't say off hand (since I didn't write the example), but if you have any particular feedback I'll be happy to send it along to the team.

Tzach K.
New member | Level 1

Hi Gregory,

I'm saying that the code example doesn't make sense. On one hand you are using async calls, but then you tell the main thread to wait for the async thread to finish, meaning you turned it into sync calls. Then why use async to begin with?

The other thing I didn't get is why you display an async call for user login. How can this be an async call? you can't do anything before the user is logged in. Same goes for other examples you provide. All of them are async but with blocking task.wait and no explanation on why you used async.to begin with. Is it because you want to show a loading gif while waiting? then why block it?

Thank you for your answer.

Qiming Y.
Dropbox Staff

The sdk provides async interface to all api calls. The example is a simple console application so the main function has to wait for the top level async call to complete. But this is not equivalent to making every api call blocking. Although the top level async task is blocking, it can still contain multiple parallel running async tasks which are non-blocking. In general any function involves network call should be async so that we can call them in parallel for better IO utilization. The login function also falls into the same category.

 

Tzach K.
New member | Level 1

Hi Qiming,

 

We say the same thing. I agree that for network you want to use async calls.

My main issue is that examples provided by DropBox should help developers understand how to build applications using your API. The explanation you provided in your answer is what needs to accompany your examples, or provide a full example.

 

Qiming Y.
Dropbox Staff

Thanks for your feedback Tzach! We will add more documentation for the examples.

Need more support?