Skip to content

Comments

Await branch: fixes and minor changes#56

Open
matcracker wants to merge 2 commits intopoggit:await-generator-supportfrom
matcracker:patch-4
Open

Await branch: fixes and minor changes#56
matcracker wants to merge 2 commits intopoggit:await-generator-supportfrom
matcracker:patch-4

Conversation

@matcracker
Copy link
Member

I was able to start the plugin with these changes but I get errors from the await library. I am attaching the crash-log. I am not very up to date on the latest changes to the await-generator library, could you help me to fix them?

$onSuccess = yield Await::RESOLVE;
$onError = yield Await::REJECT;
$this->executeSelect($queryName, $args, static function(array $rows, SqlColumnInfo $columns) use($onSuccess) : void{
$this->executeSelect($queryName, $args, static function(array $rows) use($onSuccess) : void{
Copy link
Member Author

@matcracker matcracker Mar 30, 2021

Choose a reason for hiding this comment

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

I removed $columns parameter because if you want to use it, you should use asyncSelectWithInfo(). I forgot to write this change in the description

Copy link
Member

Choose a reason for hiding this comment

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

I added the $columns parameter because I considered it as a bad practice to create a closure that accepts fewer parameters than it will be passed.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, so what would be the purpose of passing two parameters when only one will be used? This forces the user to needlessly pass a second parameter in my opinion

Copy link
Member

Choose a reason for hiding this comment

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

This does not force the user to pass a second parameter, because we are the user here. The definition of executeSelect stated clearly that two parameters will be passed, and only accepting one parameter is an antipattern in my opinion because that is not the same function signature.

Copy link
Member

Choose a reason for hiding this comment

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

Also, this is not "passing" two parameters. This is "accepting" parameters.

By the way, in await-generator 4.0.0, you cannot pass yield Await::RESOLVE to callers that pass more than one parameter, because that most likely implies a bug where you forgot to handle the remaining parameters.

Copy link
Member

Choose a reason for hiding this comment

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

Relying on the fact that passing two parameters automatically gets truncated into one parameter would cause forward compatibility problems. For example, if the caller changes to only passing one parameter (a different one), this is a BC break that should have warranted a crash, but since you always only accepted one parameter, you silently accepted the BC break without getting a crash, and hence lead to further incorrect behaviour that might damage your logic. This is dangerous.

Copy link
Member

Choose a reason for hiding this comment

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

I don't force users to always accept two arguments, but my code style requires that closures take as many parameters as they are required to, instead of silently truncating.

return $affectedRows;
//Return $affectedRows
return yield Await::ONCE;
}
Copy link
Member

Choose a reason for hiding this comment

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

since it's two lines anyway, why not make it self-explanatory instead of using a separate comment?

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.

2 participants