Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for AsyncIterator #150

Open
chr15m opened this issue Jan 22, 2024 · 0 comments
Open

Support for AsyncIterator #150

chr15m opened this issue Jan 22, 2024 · 0 comments

Comments

@chr15m
Copy link

chr15m commented Jan 22, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant