4 ms·
"best guess": API decisions are opinionated, reflecting the designers' views of how users should write code. For example, FileReader API is async in the main t
by TAForObvReasons 5y ago
"best guess": API decisions are opinionated, reflecting the designers' views of how users should write code.
For example, FileReader API is async in the main thread. There's an equivalent FileReaderSync for sync operations but that is only available in Web Workers. Why isn't FileReaderSync available on the main thread? Because the designers didn't want people to do things that would block the main thread.
The Web Worker argument probably went along the lines of "If we allow users to pass arbitrary function objects, they may try to do something that accesses local variables from the site where the worker is created. That is obviously an error, so we should design the API so that it can't happen. Creating a separate script creates a clear mental separation and avoids that class of error"