You can write custom awaitable (thenable) objects in javascript.
I think svelte (Rich harris 😅) mentioned using this to support the top level await that was introduced.
spiral into this while reading on how coroutines was designed in python.
thenables in js