Fork me on GitHub
#scittle
<
2022-12-16
>
Richie21:12:20

Does scittle not have clojure.core/promise? I don’t know how to make js/Promise work for me. I want to make a promise, put it somewhere, and deliver to it later.

Richie21:12:40

:msg "{:ex \"\\\"#error {:message \\\\\\\"Could not resolve symbol: promise\\\\\\\", :data {:type :sci/error, :line 1, :column 1, :message \\\\\\\"Could not resolve symbol: promise\\\\\\\", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 1, :column 1, :ns #object[To main], :file nil})}], :file nil, :phase \\\\\\\"analysis\\\\\\\"}, :cause #error {:message \\\\\\\"Could not resolve symbol: promise\\\\\\\", :data {:type :sci/error, :line nil, :column nil, :file nil, :phase \\\\\\\"analysis\\\\\\\"}}}\\\"\", :status [\"error\" \"done\"], :id \"354\", :session \"aef012af-d259-442d-91e3-5e1712963442\", :ns \"main\"}"

Richie21:12:22

I want to register with a websocket so that on message I deliver to the promise.

borkdude21:12:10

You can do this like this in JS:

(js/Promise. (fn [resolve reject]
  (resolve 10)) 
You can do anything you want instead of (resolve 10) to send 10 to the part of the program that's waiting on that promise

Richie21:12:21

Im trying to deliver it from the onmessage of a websocket that i registered before constructing the promise.

Richie21:12:59

Sorry. Afk atm.

borkdude21:12:32

Yeah, you can do:

(let [!resolve (atom nil) prom (js/Promise. (fn [resolve reject] (reset! !resolve resolve)))]
  (onreceive [msg] (@!resolve msg))
(pseudo-code, but you get the idea)

Richie21:12:18

I’m trying to proxy http requests through my local to get around cors.

Richie22:12:21

Taking you psuedo-code further, it would look like this.

Richie22:12:28

That does seem to work. I guess I’ll just use that for now.

Richie22:12:28

server code