Create alternate GuardClauseAssertion that supports methods marked with `async`.
See original GitHub issueAs discussed in #268, the GuardClauseAssertion
class does not wait the tasks to complete, making it unable to validate non fail fast methods.
This is completely understandable, since the fail fast is indeed the best option. Nevertheless, it seems impossible to implement fail fast behavior when dealing with methods marked with the async
keyword.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13 (10 by maintainers)
Top Results From Across the Web
Wrapping existing asynchronous code in async/await in Swift
In this post, I'll explore one of the options we have to convert existing, callback based, asynchronous code into functions that are marked...
Read more >Async/Await, Combine, Closures: A Guide to Modern ...
A comparison between async/await, Combine, and closures in Swift. Includes an overview of the strengths and weaknesses of the different ...
Read more >How Async/Await Really Works in C# - .NET Blog
So, we have Task , Task<TResult> , ValueTask , and ValueTask<TResult> . We're able to interact with them in various ways, representing ...
Read more >[Concurrency] Interoperability with Objective-C - Pitches
Hello all, Swift's concurrency feature involves asynchronous functions and actors. While Objective-C does not have corresponding language ...
Read more >Unit testing async/await Swift code
Unit testing async/await logic can be done by marking your unit test as asynchronous and using a new XCTest method.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@zvirja @aivascu could we reconsider this? I really don’t see why in 2021 async methods can’t be tested properly.
@ploeh Basically, any
async
method is not fail-fast. Consider the following example:This method doesn’t throw if you call it will
null
. Instead, the failedTask
is returned. Therefore, the GuardClauseAssertion it its current form fails and complains about missing guard clause.In real application almost all the code is
async
, therefore each invocation isawaited
and exception is thrown immediately. So it’s completely OK that “fast-fail” principle is violated in a form that you shouldawait
Task to see exception.Of course, you can re-write code somehow to make it fail immediately (create private function with
async
keyword and move all the logic there), but there is no practical sense to do it.