Fork me on GitHub
#core-async
<
2017-07-11
>
wilkerlucio17:07:32

hello, I'm trying to patch a JS promise to respond as a channel, but I guess I'm doing it wrong, can someone clarify how the ReadPort/take! method is supposed to be implemented?

wilkerlucio17:07:44

here is my current attempt (which doesn't work):

wilkerlucio17:07:46

(extend-type js/Promise
  async.protocols/ReadPort
  (take! [port f]
    (.then port f)))

wilkerlucio17:07:45

and here is the code I would like to work after that:

wilkerlucio17:07:48

(let [p (.resolve js/Promise "VALUE")]
    (go
      (let [x (<! p)]
        (js/console.log "PRO" x))))

ghadi17:07:50

rather than making another channel @wilkerlucio , have you considered doing something like:

(let [ch (chan)]
  (.then promise #(put! ch %))
  ch)

wilkerlucio17:07:25

@ghadi this is what I'm doing so far (with a wrapper function), but that is kind annoying, because then I have to do it everytime I see a promise

wilkerlucio17:07:34

would be nice if I could just use then directly

ghadi17:07:13

the f is not an actual callback but a channel 'handler' -- personally I suggest keeping your wrapper function

wilkerlucio17:07:18

it does the wrapping in a nice easy way 🙂

wilkerlucio17:07:44

because I only need to deal with the reads

wilkerlucio17:07:36

Clojure type system is so lovely 🙂

ghadi17:07:00

you can't troll us

lxsameer22:07:01

which logging library fits well with core async ?