Or: two-color functions.
The problem: async
is infectious.
There's a famous essay about this, called What Color is your Function, which I recommend reading.
For example, say you're writing a bundler. It needs to fetch resources, but is agnostic to how those resources are fetched, so it takes a readResource
function from its caller. In some contexts the caller might have those resources synchronously available; in others not. That is, caller might have a synchronous readResource
which returns a resource immediately, or an async readResources
which returns a promise for a resource, which will need to be unwrapped with await
.