I'm trying out core async, in clojurescript, to deal with promises.
ass := async-store
I can do this:
(.then (ass/set-item! "token" "value") #(print (nil? %)))
But, this doesn't work:
(go
(let [data (
How can I write that line, with core async?what do you mean doesn't work?
I get => #object [cljs.core.async.impl.channels.ManyToManyChannel]
Instead of true
It'll return a channel, but it should print true (or wtv data is)
I am not super familiar with clojurescript and the core.async side of clojurescript, but what you are seeing is the equive of the .then returning a Promise
you are seeing the go return a promise
the printing part is potentially very complicated
it could be something like js promises immediately invoke callbacks when possible and core.async always throwing callbacks in the queue to run on next tick
and I have no idea how the running on next tick stuff interacts with running a cljs repl
I refreshed the terminal where expo is running (I'm developing a project with react-native wrap). It worked.
It prints true there.
For some reason, in the cider repl it doesn't not, like I indicated in the image
it may just be that however cider is running a "cljs repl" it never lets go of the main thread so the core.async callbacks never run
It's possible set-item! errors as well when ran in the repl. Add a try/catch around it and print the error to be sure.
you could make a promise add a .then with a print to it, and then complete the promise and see if the print happens likely doesn't matter, completing the promises would trigger the callback, different strategy for running them
Yeah, as long as I can see whatever is coming through, I'm happy. Thanks for the help
I think it could also be something about where things get printed. You could check the nrepl-server buffer if it gets printed there. And I think if using figwheel, there's server-logfile so maybe it goes in a log?