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
Better onWritable documentation, and more user friendly warning on ill-use. #915
Comments
Ah so the problem is that an async function returns Promise, which is truthy. So this gets interpreted as true:
So this is actually correct, as writing nothing should return true. Only if you write inside onWritable, and fail, should you return false. So for async functions it works correctly already |
Alright I remember now. Returning false in onWritable is an optimization where the lib won't perform an extra attempt at sending, since false means the user just sent something themselves and failed. This means that all other returns than false, will try and drain the backpressure. This whole feature should be better documented to explain why onWritable wants boolean. We should accept Promise, Boolean and only warn on empty return. Currently it errors with an ugly message on empty return. |
There is a mistake in the stricness of onWritable return checks. It really only checks if onWritable returns empty or non-empty, while the real check should be if it returns a boolean or or not. The return value of onWritable must be nothing but a boolean.
This check should also have a nice, clear error message like the others we have for the 2 other checks.
The text was updated successfully, but these errors were encountered: