Aff and Promise event queues?

I have some questions about Aff.

V8 has an asynchronous completion queue. This is how JavaScript Promises are completed. https://v8.dev/blog/fast-async

Aff has its own completion queue, by @natefaubion : https://github.com/purescript-contrib/purescript-aff/blob/v5.1.2/src/Effect/Aff.js

Why does Aff need its own completion queue? What do we get from that approach that we can’t get from just using the V8 queue, as in promises?

Having two async completion queues going in the same runtime strikes me as susceptible to starvation and strange race conditions? Do we have to attend to how they interact? Is aff-promise really as effortless as it looks, @nwolverson ?

4 Likes

I guess React also has its own asynchronous completion queue. https://indepth.dev/posts/1008/inside-fiber-in-depth-overview-of-the-new-reconciliation-algorithm-in-react

So using Aff in a React app, we have three asynchronous completion queues in the runtime, each scheduling work for the one OS thread. Does this work out well in practice? In my limited experience… yes, it seems fine?

1 Like

Maybe Aff needs its own async completion queue because JavaScript Promise.resolve() flattens nested promises?

1 Like

Here’s a nice discussion of Async Programming in PureScript by @natefaubion

3 Likes

@and-pete on Slack:

Just remembered now when seeing this other video that talks about errors in Aff here for a bit:
https://www.youtube.com/watch?v=c1rJ4gwUjDg&t=1440s (starting 24mins into the video; more of a casual discussion than the other video’s presentation)
They talk for a bit about this Issue thread on errors in Aff which answers a lot about errors in Aff for me:
https://github.com/purescript-contrib/purescript-aff/issues/136
…with some further stuff you can gleam about the situation with Aff now vs where it might go in https://github.com/purescript-contrib/purescript-aff/issues/137

1 Like