Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Does your <code>getB</code> <em>have</em> to be a method which returns <code>Task&lt;B&gt;</code> rather than <code>B</code>?</p> <p>The problem is that <a href="http://msdn.microsoft.com/en-us/library/dd989582.aspx" rel="noreferrer"><code>ContinueWith</code></a> is:</p> <pre><code>public Task&lt;TNewResult&gt; ContinueWith&lt;TNewResult&gt;( Func&lt;Task&lt;TResult&gt;, TNewResult&gt; continuationFunction, CancellationToken cancellationToken ) </code></pre> <p>So in your case, because <code>getB</code> returns <code>Task&lt;B&gt;</code>, you're passing in a <code>Func&lt;Task&lt;A&gt;, Task&lt;B&gt;&gt;</code>, so <code>TNewResult</code> is <code>Task&lt;B&gt;</code>.</p> <p>If you can change <code>getB</code> to just return a <code>B</code> given an <code>A</code>, that would work... or you could use:</p> <pre><code>return ta.ContinueWith(a =&gt; getB(a.Result).Result); </code></pre> <p>Then the lambda expression will be of type, <code>Func&lt;Task&lt;A&gt;, B&gt;</code> so <code>ContinueWith</code> will return a <code>Task&lt;B&gt;</code>.</p> <p>EDIT: In C# 5 you could easily write:</p> <pre><code>public async Task&lt;B&gt; CombinedAsync() { A a = await getA(); B b = await getB(a); return b; } </code></pre> <p>... so it's "just" a matter of working out what that ends up as. I <em>suspect</em> it's something like this, but with error handling:</p> <pre><code>public Task&lt;B&gt; CombinedAsync() { TaskCompletionSource&lt;B&gt; source = new TaskCompletionSource(); getA().ContinueWith(taskA =&gt; { A a = taskA.Result; Task&lt;B&gt; taskB = getB(a); taskB.ContinueWith(t =&gt; source.SetResult(t.Result)); }); return source.Task; } </code></pre> <p>Does that make sense?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload