core-async

BuddhiLW 2024-06-18T19:58:34.612829Z

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?

2024-06-18T20:00:53.748569Z

what do you mean doesn't work?

BuddhiLW 2024-06-18T20:04:09.024349Z

I get => #object [cljs.core.async.impl.channels.ManyToManyChannel] Instead of true

2024-06-18T20:05:36.120059Z

It'll return a channel, but it should print true (or wtv data is)

2024-06-18T20:07:06.393079Z

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

2024-06-18T20:07:13.826709Z

you are seeing the go return a promise

2024-06-18T20:07:27.803839Z

the printing part is potentially very complicated

2024-06-18T20:08:19.913479Z

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

2024-06-18T20:08:38.980949Z

and I have no idea how the running on next tick stuff interacts with running a cljs repl

BuddhiLW 2024-06-18T20:08:50.949819Z

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

2024-06-18T20:09:43.801849Z

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

2024-06-18T20:10:37.912039Z

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.

2024-06-18T20:11:00.729649Z

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

BuddhiLW 2024-06-18T20:13:10.506049Z

Yeah, as long as I can see whatever is coming through, I'm happy. Thanks for the help

2024-06-18T20:19:27.734959Z

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?