Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

Tzach K.'s avatar
Tzach K.
New member | Level 1
11 years ago

async usage in examples

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

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    11 years ago

    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.'s avatar
    Tzach K.
    New member | Level 1
    11 years ago

    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.

  • 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.'s avatar
    Tzach K.
    New member | Level 1
    11 years ago

    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.

     

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

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!