Fork me on GitHub
#babashka-sci-dev
<
2022-09-01
>
Crispin06:09:01

I'm thinking about what it would take to add return values to pod async callbacks...

Crispin06:09:41

and encoding it and sending it back to the pod. with an id. and maybe into the pod with a new bencode command like retval

Crispin06:09:20

it would be up to the pod to get it to where it needs to go, with a promise or something.

Crispin06:09:56

would we make a new id and send with the invoke (this is your retval id, use it to deliver the return value)? Or could we use the existing invoke id?

Crispin06:09:43

What are your feelings on this kind of addition @U04V15CAJ? Assuming it could be done, is it something you would consider merging?

borkdude14:09:45

Hey, now looking at this message.

borkdude14:09:09

Can you describe the problem to me in terms of examples / requirements instead of proposed code changes?

Crispin14:09:23

hey! yeah. its the pod async callback

Crispin14:09:21

It would be awesome to make it possible for your callback to return a value, and that value could be sent to the pod, and used there

borkdude14:09:28

it's a while ago since I looked at it so maybe you can explain the idea to me in more general terms 😅

Crispin14:09:00

I have this bbssh pod underway. And in the pod I need to make a UserInfo class instance. And this is used by JSch to do things like, get the users password. Or ask for a passphrase for a key decryption. or some other things.

Crispin14:09:35

so when JSch calls a method on this class, like getPassword, I could fire an async callback in the bb code... maybe it would return a string. Or maybe it would prompt at the terminal. Or maybe it would open a window with a text prompt. The end user could determine that

Crispin14:09:54

but when that callback returns a value, it is just dropped

Crispin14:09:40

Its not a complete blocker, but if it were possible it would lead to a really elegant bbssh api

Crispin14:09:08

and if it is implemented, you could do even more with a pod

Crispin14:09:22

it would be pretty rarely used, but very useful to have

borkdude14:09:11

To recap for myself: In the case of the async watch function, what happens: The client calls watch, which is implemented as a client side function that calls the low level async pod api, which allows you to register a callback that gets called on 1 or more async replies (or an error handler). Those replies get sent back to the client. This is basically the same as a synchronous function call: client asks, pod sends back.

borkdude14:09:27

And now are asking beyond this, what exactly?

Crispin14:09:27

as it's not there I have to hard code the behavior here into the pod. This is the old spire UserInfo part: https://github.com/epiccastle/spire/blob/master/src/clj/spire/ssh.clj#L48-L60

Crispin14:09:04

so what Im asking is, you register the callback

Crispin14:09:11

that gets called one or more async replies (or an error handler). Those replies get sent back to the client as arguments on a :success, or a :error callback

borkdude14:09:27

yes. this already exists.. right?

Crispin14:09:39

and then... the return value of those callbacks is then send back to the pod along with the id

Crispin14:09:08

(this could be configurable somehow... or only if its not nil. Details could be worked out)

borkdude14:09:19

why - the pod sent those values to the client, why do you want to send them from the client to the pod?

Crispin14:09:51

because the client has now used those values to go and do something and return an answer that the pod needs

Crispin14:09:07

or I could invoke again?

borkdude14:09:12

shouldn't the client just call another pod function then?

Crispin14:09:40

yes. that seems obvious... :thinking_face:

Crispin14:09:04

thats basically what the response is going to do anyway

Crispin14:09:26

yep thats a good idea. a continuations style. call on with the answer

1
Crispin14:09:19

thanks! I don't know why I didn't think of that

Crispin14:09:25

too down in the weeds

borkdude14:09:33

happy to help :)

Crispin14:09:45

While I have you, one other thing I notice...

Crispin14:09:07

Is there an issue with async callback with {:transport :socket}

Crispin14:09:21

When I call it I get No matching clause

borkdude14:09:34

don't know...

Crispin14:09:49

I'll just point at the code... 1 sec

Crispin14:09:04

and then it fails on the subsequent case for the encoding

borkdude14:09:23

and what is the encoding?

borkdude14:09:44

format you mean, right?

Crispin14:09:34

yes format

borkdude14:09:54

maybe you could insert some debugging

Crispin14:09:57

Im not sure why its nil. I just started digging into this

Crispin14:09:05

just checking its not something you know about?

borkdude14:09:10

doesn't ring a bell

Crispin14:09:20

ok cool. I'll find out whats going on

Crispin14:09:44

thanks again for the clarity

🙏 1
Crispin15:09:08

OK. Its not a bug.

Crispin15:09:32

its even in the docs, but maybe it's not as clear as it could be

Crispin15:09:24

https://github.com/babashka/pods#async The arguments to babashka.pods/invoke are: a pod identifier string derived from the first described namespace.

Crispin15:09:20

Maybe a better error when you get that wrong would be good?

Crispin15:09:25

I could add that if you would accept it

borkdude15:09:30

Sounds good, if there's not much of a performance impact

👍 1
Crispin15:09:00

bedtime for me. I'll continue this tomorrow. Thanks for your help

👍 1
borkdude15:09:18

seems good, sleep well!

Crispin07:09:42

ok. amazingly I got this round trip pod->client->pod working! 🎉

Crispin07:09:55

its a bit of a dead-lock trap for the unwary

Crispin07:09:59

in particular I had to call the client->pod "return the result" call inside a future to prevent a deadlock in bb. For the brave and true who follow along in the future: https://github.com/epiccastle/bbssh/blob/0958baa17c42cb0b22f73852dcbd05a5639015dc/src/bb/pod/epiccastle/bbssh/user_info.clj#L27

Crispin07:09:05

I also had to improve my own pod mainloop code. I had some similar issues in it.

Crispin07:09:31

defined all the "methods" on the object (that lives over in the pod)

Crispin07:09:08

and they will be called in your bb code as they are called over in the pod, and your return values will be returned

Crispin07:09:13

pretty cool stuff

borkdude18:09:54

good to hear!

Crispin03:09:55

Have ended up encountering more issues here.

Crispin03:09:20

The inability to call any pod function from within a pod "method"

Crispin03:09:31

hangs bb in a deadlock

Crispin03:09:46

Im in the middle of invstigations...

Crispin03:09:51

oh, sorted it. My future for the callback had to encompass the method apply aswell... just moved my future a little further up...