mac
mac

Reputation: 10075

How to bind the resolved value of Javascript promise in ClojureScript

How do I bind the resolved return value (in this case a json object) of a Javascript promise in a let block? all I get is a #object[Promise [object Promise]]

For instance:

(.then (fn-that-returns-a-js-promise) #(print (.-prop %))) 

prints the value of prop to the the console, while:

(let [prop (.then (fn-that-returns-a-js-promise) #(.-prop %))] (print prop))

prints #object[Promise [object Promise]]

Upvotes: 2

Views: 1846

Answers (1)

Dusan Miloradovic
Dusan Miloradovic

Reputation: 43

You can't bind it.

(.then (fn-that-returns-a-js-promise) #(.-prop %))

returns javascript Promise. Every operation on a promise returns the new promise, and your program logic executes within the context of that promise, you can't escape it.

Upvotes: 1

Related Questions