forked from dsplaisted/PCLStorage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue dsplaisted#8: Async methods return faulted tasks now inst…
…ead of throwing. This is done by adding the 'async' keyword to all their method signatures. The compiler then automatically catches all thrown exceptions and returns a faulted task instead. Fixes issue dsplaisted#9: After argument validation, the next step of any async method that is otherwise synchronously implemented is to call a special method that will switch the method off its caller's thread if the caller was on their Main thread (as detected by the presence of a SynchronizationContext). This way the synchronous I/O available on that platform doesn't block the app's responsiveness, which makes the behavior consistent across all platforms and remains true to the caller's expectations since the method returns a Task. Note we don't have to do this when the platform's I/O stack is already async. As part of testing these changes, I tested passing null into methods that accept strings. I found several methods that didn't throw at all in this invalid case, or that threw the more general ArgumentException. So I added a convenient Requires class and made sure that all methods that accept string arguments call it so that the most appropriate exception type is thrown. Finally, I added tests for the method I use that switches off the caller's main thread. It only works on desktop since it requires actually setting the SynchronizationContext, which smaller framework profiles disallow (grrrr). All tests pass on all platforms.
- Loading branch information
Showing
21 changed files
with
412 additions
and
161 deletions.
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.