.net - How to apply TAP on a "partially" async method? -


i'll start explaining mean "partially" async:
have method a bunch of things. 1 of these things calling method b (fully) async. result, let a return task b , rest of a in continuation.

now a async method, before b called still synchronous. according tap async method should minimal synchronous work before returning task.

what should in situation?

these options have considered:

  1. let whatever code calls a wrap a in task.
    1. just don't postfix a "async".
    2. also don't b asynchronous either.
  2. make a asynchronous.
    1. postfix a async , wrap whole a in task.
    2. don't b asynchronous anymore because a's task wraps it.

code:

base

public task basync() {     return task.run(b); }  private void b() { /* stuff.. */ } 

option 1.1

public async task a() {     // stuff..     await basync();     // stuff.. } 

option 1.2

public void a() {     // stuff..     b();     // stuff.. } 

option 2.1

public task aasync() {     return task.run(a); }  private async task a() {     // stuff..     await basync();     // stuff.. } 

option 2.2

public task aasync() {     return task.run(a); }  private void a() {     // stuff..     b();     // stuff.. } 

i think basic principle synchronous methods should synchronous , asynchronous methods should asynchronous, there shouldn't between that.

so think option 2.1 best here.

one exception if had performance critical asp.net application. don't have ui thread there (that want keep free as possible). , might care performance penalty of running code asynchronously. in case, think option 1 appropriate (but behavior should documented).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -