Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more doc comments for handling user-supplied callbacks for cloud-to-device communication #2939

Merged
merged 4 commits into from
Nov 9, 2022

Conversation

brycewang-microsoft
Copy link
Contributor

@brycewang-microsoft brycewang-microsoft commented Nov 8, 2022

Also add internal exception handling for those user-supplied callbacks.

I don't feel confident about good places for putting these doc comments to share with users, so open to any suggestions.

@@ -79,6 +79,11 @@ public abstract class IotHubBaseClient : IDisposable
/// <summary>
/// The callback to be executed each time connection status change notification is received.
/// </summary>
/// <remarks>
/// This user-supplied callback is "fire-and-forget" and the SDK doesn't wait on it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have reference or document to point out what are the exceptions the user can expect?
What about updating the example with 'try/catch' to explicitly remind the user about handling exceptions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call the user's callback, therefore we can't throw exceptions that would impact them here. However, if they throw an exception, we need to handle it so as to not crash the process. We're just fixing and documenting that behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific callback doesn't return anything (Action<ConnectionStatusInfo>), so instead of calling this fire-and-forget (which would mean that it returns a task but we don't await on it) why don't we call out that only if you put async code within this callback, you'll need to handle exceptions that could originate in there?

Co-authored-by: David R. Williamson <drwill@microsoft.com>
@brycewang-microsoft
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@brycewang-microsoft
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@brycewang-microsoft brycewang-microsoft merged commit 9ad906d into previews/v2 Nov 9, 2022
@brycewang-microsoft brycewang-microsoft deleted the brycewang/callback branch November 9, 2022 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants