Created
July 25, 2014 16:12
-
-
Save jamesrcounts/e68ae4b3aae2ba7b0bb3 to your computer and use it in GitHub Desktop.
A more convenient way to write a saver when you want async
This file contains hidden or 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
| // New interface... | |
| using System.Threading.Tasks; | |
| public interface IAsyncSaver<T> | |
| { | |
| Task<T> Save(T item); | |
| } | |
| // Old way... | |
| ISaver<Task<FileInfo>> saver = new AsyncFileSaver(); | |
| FileInfo foo = new FileInfo("foo"); | |
| // here we create a task for no reason other than to conform to | |
| // the interface. | |
| FileInfo bar = await saver.Save(Task.FromResult(foo)); | |
| // New way... | |
| IAsyncSaver<FileInfo> saver = new AsyncFileSaver(); | |
| FileInfo foo = new FileInfo("foo"); | |
| FileInfo bar = await saver.Save(foo); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment