August 21, 2021
Inside Out Async
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.

Francis 🏴☠️ Gulotta


Francis 🏴☠️ Gulotta

Francis 🏴☠️ Gulotta

Francis 🏴☠️ Gulotta

Francis 🏴☠️ Gulotta


Francis 🏴☠️ Gulotta
![it('queues up values until queueError is called', async () => {
const deferred = deferGenerator<number, undefined>()
deferred.queueValue(1)
deferred.queueValue(2)
deferred.queueValue(3)
deferred.queueError(new Error('oh no!'))
const values: number[] = []
try {
for await (const val of deferred.generator) {
values.push(val)
}
throw new Error('should have errored')
} catch (e) {
assert.equal(e.message, 'oh no!')
}
assert.deepEqual(values, [1, 2, 3])
})](/_next/image/?url=https%3A%2F%2Fassets.toot.cafe%2Fmedia_attachments%2Ffiles%2F106%2F724%2F124%2F442%2F861%2F736%2Foriginal%2Fe00ddf77e1e0d2d3.jpeg&w=3840&q=75)

Francis 🏴☠️ Gulotta

Francis 🏴☠️ Gulotta

Francis 🏴☠️ Gulotta

Roborooter.com © 2023
Powered by ⚡️ and 🤖.
Powered by ⚡️ and 🤖.