Sequential computation macro
- Dominant language
- Clojure
- Stars
- 547
- Forks
- 64
- PR merge metrics
- No merged PRs in 30d
Description
It would be great if there was a way to run a series of promises sequentially, waiting for the previous one to finish, and return a vec of all promises for use with `p/all`. This is different to creating a map of promise returning functions as that would run in parallel not sequentially. See [discussion on Slack here](https://clojurians.slack.com/archives/C03S1L9DN/p1702741749869629).
Here is an implementation using `reduce`:
```clojure
(p/let [result
(p/all
(reduce
(fn [col panel-choice]
(conj col
(p/let [_ (last col)]
(something-returning-promise panel-choice))))
[]
panel-choices))]
(print "reduce" result))
```
Here is an implementation using `p/loop` and `p/recur`:
```clojure
(p/let [result
(p/loop [choices panel-choices results []]
(if (empty? choices)
results
(p/let [result (something-returning-promise
(first choices))]
(p/recur (rest choices)
(conj results result)))))]
(print "loop/recur" result))
```
You can test this in `nbb` with `promises.cljs` here:
https://gist.github.com/chr15m/c5f943b6aa2c6089c04f04897b3cef81
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the sequential examples in nbb with the referenced promises.cljs gist, comparing the reduce and p/loop approaches against p/all. Review the existing promise and macro entry points in promesa to determine where the requested API belongs; done means a documented way to collect promise results sequentially while preserving the intended waiting behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100