funcool / funcool/promesa

Support for AsyncIterator

Open
#150 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Clojure
Stars
547
Forks
64
PR merge metrics
No merged PRs in 30d

Description

Occasionally an API requires the use of a JavaScript async `for` over some iterator like this:

```javascript
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](https://ask.clojure.org/index.php/10896/how-to-work-with-asynciterable-interface-in-cljs). Here's the macro:

```clojure
(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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing Promesa's existing asynchronous API alongside the linked async-doseq macro and the JavaScript AsyncIterator example. The issue names no files or tests, so first locate the relevant iteration and promise entry points; done should be defined as documented support for consuming an async iterable with clear completion semantics and coverage for the intended usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.