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

why readFileSync and writeFileSync instead of having promises? #266

Closed
mreinstein opened this issue Jun 17, 2018 · 5 comments
Closed

why readFileSync and writeFileSync instead of having promises? #266

mreinstein opened this issue Jun 17, 2018 · 5 comments

Comments

@mreinstein
Copy link
Contributor

Looking at the roadmap document, I see the 2 exposed filesystem calls use the node similar syntax of
readFileSync and writeFileSync, but the fetch call returns a promise. I'm wondering why not just make readFile and writeFile be promise based and consistently return a promise event for any of these "will complete in the future" API calls?

@ry
Copy link
Member

ry commented Jun 17, 2018

We can have those too, but sync file I/O is more often what is needed, and what we'll be implementing first.

@mreinstein
Copy link
Contributor Author

ah ok, that seems reasonable if you think sync i/o is more common. Just wanted to make sure we weren't following a legacy node-ism unnecessarily. Thanks for the clarification.

@ZanderBrown
Copy link

When you consider await is there any difference as such?
(obs there is but hopefully you get the point)

@ry
Copy link
Member

ry commented Jun 17, 2018

@ZanderBrown Yes- the sync methods can call directly into sync syscalls. The awaited async methods go through a thread pool and then polling for completion on the event loop - which ends up being slower in most cases.

@mreinstein
Copy link
Contributor Author

^ ^ ^ ^ ^

This is probably the only lamentable thing I've encountered with async/await. It makes code appear synchronous syntactically but under the hood it's not.

piscisaureus pushed a commit to piscisaureus/deno that referenced this issue Oct 7, 2019
humancalico pushed a commit to humancalico/deno that referenced this issue Aug 24, 2020
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

No branches or pull requests

3 participants