Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:04:59+00:00 2026-06-18T00:04:59+00:00

I’m developing a class library (for use by other developers) which wraps a RESTful

  • 0

I’m developing a class library (for use by other developers) which wraps a RESTful web service. I’m using the HttpClient type from the System.Net.Http namespace to do all of my API calls, asynchronously.

In addition to simply sending/receiving content, I want to do additional processing on the returned XML data. No matter how you put it, this involves using the Async/Await keywords somewhere in the class library.

My question is whether it’s a good or bad idea to expose methods which use the Async keyword, and why. I’ve read somewhere that you should make the Async method private, then create an additional method with just a return statement. That’s what I’ve been doing, but it doesn’t feel right.

Public Function InvokeAsync(command As HttpRequestMessage) As Task(Of CommandResult)
    Return InvokeAsyncInternal(command)
End Function

Private Async Function InvokeAsyncInternal(command As HttpRequestMessage) As Task(Of CommandResult)
    Dim rawCommandResult As HttpResponseMessage = Await myHttpClient.SendAsync(command)
    Dim finalResult As CommandResult = AdditionalProcessing(rawCommandResult)
    Return finalResult
End Function

Keeping in mind that this is an oversimplified code sample: are there any good arguments not to expose the Async method directly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:05:00+00:00Added an answer on June 18, 2026 at 12:05 am

    This has to do with the compiler transformation; you can separate the “real” Async method from its Public counterpart, and you get the same benefits as when you do the same kind of separation for iterator (Yield) methods.

    In particular, exceptions are handled differently when thrown from the wrapper than when thrown from the Async method. When an Async method that returns Task throws an Exception, it’s placed on the returned Task rather than thrown directly to the caller. When the Public wrapper method (which is not Async) throws an Exception, it’s thrown directly to the caller.

    So, precondition-style checks can be put in the Public method. Callers can ignore exceptions placed on Tasks, but they can’t ignore exceptions thrown directly. Placing precondition exceptions in a Public wrapper forces the caller to realize they are misusing the API, and also permits a separation of usage exceptions (which are thrown directly) from runtime exceptions (which are placed on the Task).

    If your method has no preconditions, then your Public wrapper is just returning the inner Task. In this case, the Public wrapper is unnecessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am using JSon response to parse title,date content and thumbnail images and place
I used javascript for loading a picture on my website depending on which small
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm interested in microtypography issues on the web. I want a tool to fix:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.