Hia, I’m having trouble converting the following code to d/loop
:
(loop [messages (fetch-messages auth-token query nil)
result []]
(let [next-token (:nextPageToken messages)]
(if (nil? next-token)
(d/future (concat result (:messages @messages)))
(recur (fetch-messages auth-token query next-token)
result))
))
I must have misunderstood something, this is my attempt:
(d/loop [messages (fetch-messages auth-token query nil)
result []]
(-> messages
(d/chain
(fn [msgs]
(let [next-token (:nextPageToken msgs)]
(println "NEXT:" next-token)
(if (nil? next-token)
(concat result (:messages msgs))
(d/recur (fetch-messages auth-token query next-token))
)
)))
(d/catch
(fn [ex]
(println "ERROR" ex)
ex))
))
mping: it looks like you're d/recur
is missing one argument, it should probably be something like this (didn't check with compiler):
(d/loop [token nil
result []]
(-> (fetch-messages auth-token query token)
(d/chain
(fn [msgs]
(let [next-token (:nextPageToken msgs)]
(println "NEXT:" next-token)
(if (nil? next-token)
(concat result (:messages msgs))
(d/recur next-token (concat result (:messages msgs)))))))
(d/catch
(fn [ex]
(println "ERROR" ex)
ex))))
nvmind, found a bug
was missing an argument to d/recur
:troll: