Deno: why readFileSync and writeFileSync instead of having promises?

Created on 17 Jun 2018  路  5Comments  路  Source: denoland/deno

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?

Most helpful comment

@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.

All 5 comments

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

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.

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

@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.

^ ^ ^ ^ ^

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zugende picture zugende  路  3Comments

ry picture ry  路  3Comments

JosephAkayesi picture JosephAkayesi  路  3Comments

xueqingxiao picture xueqingxiao  路  3Comments

justjavac picture justjavac  路  3Comments