joyride

pez 2022-05-12T08:01:36.867479Z

Input wanted: https://github.com/BetterThanTomorrow/joyride/discussions/58 🙏

zimablue 2022-05-12T16:42:10.109179Z

Is TCL unable to access native JS promises? in order to VSCode interop it must be able to communicate with JS

borkdude 2022-05-12T16:52:01.296939Z

What is TCL?

zimablue 2022-05-12T16:53:04.713209Z

I meant TCI, corrected below sorry

borkdude 2022-05-12T16:53:26.695859Z

What is TCI?

zimablue 2022-05-12T16:53:52.063299Z

my bad

zimablue 2022-05-12T16:53:53.090349Z

SCI

zimablue 2022-05-12T16:53:55.794139Z

I'm going mad

zimablue 2022-05-12T16:54:07.040059Z

synonyms for "little" small, tiny, teeny

borkdude 2022-05-12T16:54:34.320789Z

SCI can access native JS promises

zimablue 2022-05-12T16:54:47.007239Z

I was just trying to understand the problem, as I had a very similar one in cljs and the simplest solution seemed to be to just thinly wrap JS promises

borkdude 2022-05-12T16:55:17.747469Z

yes, this is already what happens with promesa which is exposed in #nbb and #joyride (both based in SCI)

borkdude 2022-05-12T16:55:48.416179Z

e.g.:

(p/let [x (p/delay 1000 :hello)] x)
returns a promise that returns :hello after 1 second

zimablue 2022-05-12T16:56:12.967139Z

got you, I don't understand the question then

borkdude 2022-05-12T16:56:48.591029Z

well, JS has something like:

const x = await(...)

zimablue 2022-05-12T16:56:52.453919Z

a top level def employing an async thing has to either block or return a promise/channel/callback, so one can already use promises, can one block?

borkdude 2022-05-12T16:57:09.997929Z

blocking is not possible and await is also not possible in CLJS normally

zimablue 2022-05-12T16:57:24.461419Z

the closest is (<p!) right, (def ting (<p! other thing)) or (def tong (promise-wrapper (async-fn))

borkdude 2022-05-12T16:57:26.370709Z

but #nbb evaluates differently

borkdude 2022-05-12T16:57:50.226379Z

well, (def ting (<!p ...)) still makes ting a promise, not the value "inside" the promise

zimablue 2022-05-12T16:58:09.859999Z

exactly, so the question is: can we surface nbb's ability to block?

borkdude 2022-05-12T16:58:30.770389Z

yes, that's is what sci.async is becoming

borkdude 2022-05-12T16:58:38.028939Z

and then joyride can use that

borkdude 2022-05-12T16:58:56.936379Z

Read more here: https://github.com/babashka/sci/blob/master/doc/async.md

zimablue 2022-05-12T17:01:21.851639Z

so the macro is moving the async from top-level 'inside' the def to 'outside' the def, failing pseudocode like (defmacro my-def [form]) (if (first-thing-in-form-is-<!) (let [res (<! (rest of form))] (def name res)) (def name (form)))

zimablue 2022-05-12T17:01:42.018409Z

sorry that's definitely wrong but do I get the gist? Could this be expressed as a macro in cljs?

zimablue 2022-05-12T17:01:59.076139Z

it's an interesting approach, I just accepted that I was going to have to unwrap a lot of promises

pez 2022-05-12T17:14:58.178339Z

tcl brings back memories. 😀

zimablue 2022-05-12T17:17:15.885649Z

I apologize to anyone who had to read the first part of this thread for my brain

zimablue 2022-05-12T17:17:53.634749Z

is my question re the macro 'correct'? like if one defined defp with roughly the control flow I described, it would be equivalent?

zimablue 2022-05-12T17:18:10.208239Z

I might actually do that it's more comfortable than all this unwrapping

zimablue 2022-05-12T17:22:29.908729Z

I guess one problem would be if you block before running def then references to that def that resolve before it completes will blow up, SCI's approach can work because it can 'block' global execution, in clojurescript one would need to either spin or use 'delay'?

zimablue 2022-05-12T16:42:35.643729Z

the normal pattern would just be (<p!)?

zimablue 2022-05-12T16:43:49.567639Z

one can 'hack' JS promises too by capturing their request, resolve functions so that they can be resolved later, so since this creates a chain of definitions, you can choose to either make those defs return channels or promises

zimablue 2022-05-12T16:44:00.301249Z

*TCI

zimablue 2022-05-12T16:44:42.904259Z

I had to do something like this in my (cljs) electron app and just used native promises

zimablue 2022-05-12T16:47:10.929729Z

sorry by resolved later I mean resolved from outside their scope if that makes sense, making them act more like clojure promises

borkdude 2022-05-12T20:28:45.156609Z

Now playing 🎵

🎸 1