This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-11
Channels
- # aws (15)
- # beginners (55)
- # boot (116)
- # bristol-clojurians (2)
- # cider (4)
- # cljs-dev (439)
- # cljsrn (14)
- # clojure (135)
- # clojure-argentina (3)
- # clojure-czech (4)
- # clojure-italy (60)
- # clojure-russia (1)
- # clojure-spec (48)
- # clojure-uk (42)
- # clojurescript (170)
- # cloverage (11)
- # core-async (19)
- # cursive (13)
- # datomic (48)
- # emacs (2)
- # graphql (3)
- # hoplon (8)
- # jobs (1)
- # jobs-discuss (5)
- # klipse (11)
- # luminus (5)
- # lumo (5)
- # mount (48)
- # off-topic (96)
- # om (17)
- # onyx (14)
- # parinfer (30)
- # protorepl (1)
- # re-frame (90)
- # reagent (2)
- # remote-jobs (1)
- # spacemacs (12)
- # specter (20)
- # uncomplicate (1)
- # untangled (65)
- # vim (2)
- # yada (8)
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?
here is my current attempt (which doesn't work):
(extend-type js/Promise
async.protocols/ReadPort
(take! [port f]
(.then port f)))
and here is the code I would like to work after that:
(let [p (.resolve js/Promise "VALUE")]
(go
(let [x (<! p)]
(js/console.log "PRO" x))))
rather than making another channel @wilkerlucio , have you considered doing something like:
(let [ch (chan)]
(.then promise #(put! ch %))
ch)
@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
would be nice if I could just use then directly
the f
is not an actual callback but a channel 'handler' -- personally I suggest keeping your wrapper function
see https://github.com/clojure/core.async/blob/105acd5b40a66b6d1c80271a30ae273c6933c5bd/src/main/clojure/cljs/core/async/impl/channels.cljs#L44-L163 for the channel implementation. It's not trivial...
@ghadi thanks, actually I found just what I was looking for here: https://github.com/jamesmacaulay/cljs-promises/blob/master/src/cljs_promises/async.cljs#L21-L35
it does the wrapping in a nice easy way 🙂
because I only need to deal with the reads
Clojure type system is so lovely 🙂
another nice type system on display here @wilkerlucio https://github.com/LuxLang/lux/blob/master/stdlib/source/lux/type/auto.lux#L308