Apparently, your wrote in the specifications of Method1 that this function would do something that requires you to call Method2, otherwise you could write your procedure without calling Method2.
This means, that your caller expects some post condition. Alas you didn't write your post condition, so I have to write the following using fairly abstract terms.
Suppose Method2 has a post-condition Post2 (I'm leaving the pre-condition here out of the discussion)
Now what did you write as specification of Method1? I know you wrote a simplified version of your actual Method1, but it seems to be something like:
Method2 will return a Task<string>
, that, when awaited for, will have changed the state of the process into: Post2 AND the return value will be a string containing "some text".
If this is your specification, then you definitely should await for Method2.
An alternative specification could be:
Method2 will return a Task<string>
, that, when awaited for, will have started Method2 AND the return value will be a string containing "some text".
If this is the case, you don't have to await for Method2. Your caller has no way to find out when Post2 is active, nor whether a problem occurred when trying to change the state of the machine to Post2.
It might be that at some point one of your callers want to be certain that Method2 has completed, and thus Post2 is met. Why don't you let the caller decide whether he wants to await for Method2?
Instead of returning Task<string>
, you could return a Tuple containing the Task for Method2 and the returning string. See Tuples in C# 7
public (string Text, Task Task> Method1()
{
string s = "some text";
Task method2Task = method2();
return (Text: s, Task: method2Task);
}
Because you don't await, the method isn't async anymore.
Of course you can make do it in one statement:
return (Text: "Some text", Task: method2() );
Your caller should to something like:
var method1Result = method1();
// I'm not interested in Method2 right now, but I like to process the string result
ProcessText(method1Result.Text);
// if, after a while I want to be certain the Post2 is met, I'll have to await:
await method1Result.Task