Skip to content

Make the API less asynchronous#51

Merged
dhdaines merged 6 commits intomasterfrom
async_considered_harmful
Dec 19, 2022
Merged

Make the API less asynchronous#51
dhdaines merged 6 commits intomasterfrom
async_considered_harmful

Conversation

@dhdaines
Copy link
Contributor

@dhdaines dhdaines commented Dec 19, 2022

Perhaps it's common knowledge to JavaScript programmers but async and await are not general purpose coroutines, that is to say, an async function does not necessarily suspend execution on each await in the sense of unblocking the main event loop. This is because Promises run on the "microtask queue" and the browser will keep running them until there are no more left before it goes back to doing important things like responding to user input: https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide#microtasks

Obviously if you launch a bunch of async functions or Promises they will yield to each other but that is not actually what you want in most cases.

Concretely this means that using async for CPU-bound APIs is considered harmful (tm). So we have to remove async from most functions in the API.

Conversely, for IO-bound APIs it is considered useful (tm). So initialization will definitely remain async/promise based.

async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
async/await are not coroutines
@dhdaines dhdaines changed the title Make the API less asynchronouse Make the API less asynchronous Dec 19, 2022
@dhdaines dhdaines merged commit 4a003fd into master Dec 19, 2022
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

Successfully merging this pull request may close these issues.

1 participant