Fork me on GitHub
#joyride
<
2023-07-09
>
chromalchemy18:07:32

Can I write to a file with joyride? I assume i can use nbb fs package via NPM deps? (haven’t tried it yet) Or use vscode extension fs api?

borkdude18:07:13

You can use Node's fs lib

borkdude18:07:29

fs/writeFileSync I believe

chromalchemy18:07:11

Ok thanks, maybe another generic question: Also I tried this fn, but not sure how to read promise it returns. (vscode/workspace.fs.readDirectory ".")

borkdude18:07:45

use promesa:

(p/let [dir (vscode/workspace.fs ...])

chromalchemy18:07:49

(p/let [dir (vscode/workspace.fs.readDirectory ".")]
   dir)
=> #<Promise[~]>

chromalchemy18:07:35

Not sure how to get the value, or if I’m invoking the vscode fn correctly.

borkdude18:07:35

you don't get the value, you program with promises

borkdude18:07:13

if you print dir it will have the value, but the result of the entire expression will always be a promise, you can't escape this

chromalchemy18:07:09

Ok thanks! I’m still not getting value, but maybe I have vscode fn wrong (construct uri better?)

(p/let 
   [dir (vscode/workspace.fs.readDirectory "file:///Users/")]
   (print dir)) 

=> #<Promise[~]>

borkdude18:07:05

the expression returns a promise, but what is printed is the dir

borkdude18:07:23

not the return value of the expression that is printed, but the print as a side effect

borkdude18:07:17

For example, try:

(def the-dir dir)
inside of your p/let

borkdude18:07:23

then eval the expression and then eval the-dir

borkdude18:07:31

you should see a non-promise value in there

Jason Whitlark15:07:21

I got stuck on that too, a while back. I think that would be good to add to the joyride docs; I came from jvm clojure, and this was one of the stumbling blocks.

borkdude15:07:35

read/do the promesa tutorial

chromalchemy17:07:15

Will do, thanks