-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
FileSystemAccess.prototype.readText has an async interface, but is synchronous #537
Comments
Indeed file access is synchronous for now however once we have support for background workers/threads we will improve this. |
Till then, the API should be renamed to, e.g., Node style's |
I think we should emphasize on the usage of the |
As per #554 (comment) this might just not yet be finished. |
The onError parameter is optional and it actually provides another means to |
Hey. You're right, it's not really the best solution for a synchronous API. It reinvents what try-catch is there for. It's also not clear to read as why should a synchronous API take a callback. I haven't checked how the async versions now behave (perhaps there still aren't any). Anywho, synchronous APIs in JavaScript should stick to returning a value or throwing an exception. Theoretically that could be implemented in union types to forgo exceptions, but I wouldn't. Most other [sync] APIs are exception based here. https://www.joyent.com/developers/node/design/errors is a decent enough reference to start thinking about error design. Once you get to async interfaces, I wouldn't invent the wheel either. Promises or Node.js style continuation-passing with the same error API and you're good to go. ;-) Feel free to give me a call someday if you want to chat about APIs. |
@moll thanks for the heads-up :) I tend to agree with you and the suggested way for error handling. Truth is the |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hey,
I was going through the source code and stumbled upon something pretty weird.
That's an async interface, but according to https://github.com/NativeScript/NativeScript/blob/5e5d75c09d8a3a49bbf6de5bfa53bc1736e99de4/apps/tests/file-system-access-tests/file-system-access-tests.ts and its use in
builder.ts
, it works synchronously. That's zalgo right there. A sync interface is handy, but the weird interface is, well, weird. It should return the content of the file on success and throw on error.Cheers.
The text was updated successfully, but these errors were encountered: