I nerdsniped myself and made a handy async utility that turns Promises and AsyncGenerators inside out. This is very handy for testing and useful if you’re done non trivial transformations of events into async generator or promised based apis. I call it Inside Out Async.

My development journey was posted in realtime and preserved below.

This thread can be found at toot.cafe includes 9 statuses.

This is my favorite little function, `defer()` it's an inside out promise

Now how to make this for an async iterator? 🤔

Generators and AsyncGenerators behave differently besides the obvious.

if you keep calling .next() after it's done, async generators will persist the return value where as generators will not - The spec is hard to read so I don't know if it's a spec thing or a nodejs/v8 thing.

I have nerdsniped myself in the worst way with this

I don't even remember why I wanted this, but it feels good.

ok I was going to use this for a test or something but I don't remember

The deferGenerator() really cleans up this test. I basically passing a bunch deferred promises back before which did not work well.