I have two methods that are similar, however, after theorizing about this, I'm pretty sure they are different in execution.
MethodOne:
var renderDocumentDirective = await
RenderDocumentBuilder.Instance.GetRenderDocumentDirectiveAsync(previousPage, session);
return await ResponseClient.Instance.BuildAlexaResponse(new Response()
{
shouldEndSession = null,
directives = new List<IDirective>()
{
renderDocumentDirective
}
}, session.alexaSessionDisplayType);
MethodTwo
var renderDocumentDirective = RenderDocumentBuilder.Instance.GetRenderDocumentDirectiveAsync(previousPage, session);
return await ResponseClient.Instance.BuildAlexaResponse(new Response()
{
shouldEndSession = null,
directives = new List<IDirective>()
{
await renderDocumentDirective
}
}, session.alexaSessionDisplayType);
The first method uses the await operator on the async task, RenderDocumentBuilder, prior to its uses inside the ResponseClient, which is also an async task.
However the second method, sets up the Task RenderDocumentBuilder, but doesn't call the awaited method until it is inside the ResponseClient, which, at this point in execution, is waiting to return data.
Both ways of executing this method work, but I am unclear if it is proper to:
await a task outside the ResponseClient? (method 1)
Or, is it proper to create the renderDocumentDirective Task outside the ResponseClient and await it inside the method? (method 2)
new Response()calls have some strange side effects they are pretty much the same.GetRenderDocumentDirectiveAsyncin the first example.ResponseClient.Instancematter? The entire expression is evaluated before awaiting anyway.