Prism
Prism copied to clipboard
[BUG] Task Extensions .Await completed callback can trigger error callback
Description
When Await() is used with a callback and errorCallback, an exception in the callback can trigger an errorCallback.
I think this is kind of counterintuitive - the errorCallback should be about the task you're awaiting on only, and you should either
A) get some kind of guarantee that only the completed callback or the error callback is going to be triggered or
B) completed callback will always be run, and error will only be run if there's an error in the Task
Steps to Reproduce
Console.WriteLine("Hello, World!");
Task.Delay(1000).Await(()=> {
Console.WriteLine("completed");
throw new Exception("Unrelated exception");
}, ex=>Console.WriteLine(ex.Message), true);
Console.ReadKey();
Platform with bug
Prism Core
Affected platforms
Windows
Did you find any workaround?
No workaround, but it should be easily resolved by moving completedCallback?Invoke() line outsideof the try/catch and adding a return after errorCallback invoke OR moving the completed callback to a finally block, depending on what behaviour is desired.
Relevant log output
Hello, World!
completed
Unrelated exception
In case of an exception the completed callback should not fire at all, only the error call back.
Would you like to submit a PR?
Can do I think this could be done as a shorthand wrapper around Task.ContinueWith as well. What approach would you prefer?
Please avoid using ContinueWith.
Closing this as there we no longer any interest in moving this forward.