Last active
August 29, 2015 14:06
-
-
Save alextercete/a011bafde7187104303b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
namespace AsyncAndAwaitSecrets.Samples | |
{ | |
public class AsyncAndAwait<T> | |
{ | |
private readonly IDependency<T> _dependency; | |
public AsyncAndAwait(IDependency<T> dependency) | |
{ | |
_dependency = dependency; | |
} | |
public async Task<T> SomethingAsync() | |
{ | |
var result = await _dependency.BeforeAsync(); | |
return await _dependency.AfterAsync(result); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
namespace AsyncAndAwaitSecrets.Samples | |
{ | |
public interface IDependency<T> | |
{ | |
Task<object> BeforeAsync(); | |
Task<T> AfterAsync(object result); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
namespace AsyncAndAwaitSecrets.Samples | |
{ | |
public class TaskParallelLibrary<T> | |
{ | |
private readonly IDependency<T> _dependency; | |
public TaskParallelLibrary(IDependency<T> dependency) | |
{ | |
_dependency = dependency; | |
} | |
public Task<T> SomethingAsync() | |
{ | |
return _dependency.BeforeAsync() | |
.ContinueWith(previous => _dependency.AfterAsync(previous.Result)) | |
.Unwrap(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment