-
-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Description
Occasionally an API requires the use of a JavaScript async for
over some iterator like this:
for await (const [key, value] of this.keyv.iterator()) {
console.log(key, value); // Return: key and value
};
It would be neat if there was a way to do this directly in promesa, similar to the macro at How to work with asynciterable. Here's the macro:
(defmacro async-doseq [[binding async-iterable] & body]
`(let [async-iterator# ((js* "~{}[Symbol.asyncIterator]" ~async-iterable))]
(fn handle-next# []
(let [next# (.next async-iterator#)]
(.then
next#
(fn [res#]
(if (.- res# done)
nil
(do (let [~binding (.- res# value)]
~@body)
(handle-next#)))))))))
Is this something Promesa is interested in supporting?
Metadata
Metadata
Assignees
Labels
No labels