-
Notifications
You must be signed in to change notification settings - Fork 933
NH-4092 - AsyncGenerator creates unused private static event handler in SQLite20Driver #712
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
Conversation
/// <exception cref="Exception"> | ||
/// If there is any problem creating or opening the <see cref="DbConnection"/>. | ||
/// </exception> | ||
public override async Task<DbConnection> GetConnectionAsync(CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how this went away. It still uses conn.OpenAsync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know. There may be some issues in the AsyncGenerator. I tried various ways to try to exclude SQLite20Driver
from being generated and it always made all these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maca88 can you please investigate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maca88 There is this warning in the generate-async task log on the current master branch (before these changes):
[exec] INFO ProjectAnalyzer:0 - Analyzing documents started
[exec] WARN ProjectAnalyzer:0 - Cannot attach an async method to an event (void async is not an option as cannot be awaited):
[exec] connection.StateChange += Connection_StateChange
[exec]
[exec] INFO ProjectAnalyzer:0 - Analyzing documents completed
What is the correct way to keep the un-used/un-needed private static method from being generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the correct way to keep the un-used/un-needed private static method from being generated?
Currently, the generator is not smart enough to skip generating un-used private methods, I will try to add support for it.
For un-needed methods, you have to add them in the configuration as you did, but it seems that for this particular method something is not right as GetConnectionAsync
is removed even if there is still one async method used (OpenAsync
). I will investigate it when I get home.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added support for skipping the generation of unused methods, just by updating to the new version 0.5.1
the method Connection_StateChange
won't be generated anymore.
Here is why the GetConnectionAsync
goes away when ignoring Connection_StateChange
:
With the current settings GetConnection
has the conversion set to Unknown
when the generator starts scanning, which means that the generator will convert this method to async only if one of the async marked method is called/referenced inside GetConnection
method.
Before this change, the GetConnection
was generated because of the following dependencies:
IBatcher.ExecuteNonQuery
which has the conversion set toAsync
within the configuration- Inside
IBatcher.ExecuteNonQuery
method body,DbCommand.ExecuteNonQuery
was found to have an async counterpart SQLite20Driver.Connection_StateChange
was found because uses theDbCommand.ExecuteNonQuery
methodSQLite20Driver.CreateConnection
was found because uses theConnection_StateChange
methodDriverConnectionProvider.GetConnection
was found beause usesIConnectionProvider.CreateConnection
- Inside
DriverConnectionProvider.GetConnection
method body,DbConnection.Open
was found to have an async counterpart
By ignoring SQLite20Driver.Connection_StateChange
method, the generator will stop at point 3, which means that DriverConnectionProvider.GetConnection
will never be scanned and consequently not generated. So the solution (if we ignore the new version) would be, to set the conversion of GetConnection
method to Async
or Smart
in order to have its method body scanned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @maca88 for the quick turn-around on this. Updating to the new version found a few more un-used private functions that were being generated.
Update AsyncGenerator and regenerate async files.
Addresses NH-4092.
Exclude
SQLite20Driver.Connection_StateChange
in AsyncGenerator.yml and regenerate async files.If it is ok for the
Connection.StateChange
event to call a fire-and-forget event handler, then the primary event handler method can be modified to anasync void
.