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

Make the API less asynchronous #51

Merged
merged 6 commits into from
Dec 19, 2022
Merged

Make the API less asynchronous #51

merged 6 commits into from
Dec 19, 2022

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