Fork me on GitHub
#code-reviews
<
2015-09-26
>
bhagany16:09:48

So, I realize this room is probably going to be even less active with Strange Loop on, but here goes nothing. Context: I have a cljs project that runs on AWS Lambda, which pretends to have a real database by serializing a Datascript db to S3, and deserializing/instantiating it again whenever a relevant Lambda function is run. That basic functionality works acceptably. However, now that Component works in cljs, I am trying it out by creating a component for this Datascript thing, but the asynchronous nature of getting an object from S3 is kind of throwing me off.

bhagany17:09:04

I started out really wanting to assoc the conn atom into the component, but I think I have to be content with the channel.

bhagany17:09:24

So I guess my questions are: 1) am I correct that there's no real good way to put the conn in the component, and thereafter treat it as though it was a synchronous thing, like a normal db connect, and if so, 2) am I doing it right in that gist.

danielcompton19:09:42

@bhagany: what’s the benefit of creating a go-loop?

danielcompton19:09:52

I think that could be a go block

danielcompton19:09:18

It doesn’t seem like it ever recurs?

bhagany19:09:39

@danielcompton: I want to be able to take from conn-ch multiple times, and get the same conn back

bhagany19:09:50

ah, I did forget to recur

bhagany19:09:35

I am not entirely certain this will work the way I envision - never used a go-loop before

danielcompton19:09:01

I think you’ll need to return a channel if you want the go-loop to keep running

bhagany19:09:01

go-loop itself doesn't return a channel?

bhagany19:09:23

hmmm, but there's nothing that parks it if conn exists...

bhagany19:09:05

and I believe I'm trying to treat the record as a mutable thing. so this doesn't work on multiple levels.

bhagany19:09:33

but, that leaves me with very little idea about how to create a component out of something with an async start

bhagany19:09:39

@danielcompton: updated the gist with a new attempt

danielcompton19:09:24

I don’t know enough about component to comment much further sorry

bhagany19:09:35

no problem, thanks for taking a look simple_smile

potetm20:09:04

@bhagany: Let me get this straight. You want to initialize the db (aka conn in datascript) in that start fn?

potetm20:09:33

And you want it to block while you do that?

bhagany20:09:38

@potetm: yes, that's right, if it's possible

bhagany20:09:53

otherwise return a channel that constantly gives me the same connection

potetm20:09:55

hmm… that’s a toughie

bhagany20:09:50

yeah… I'm relatively happy with being able to take from a channel, which I'm pretty sure I can do. Unfortunately I can't really test this until I convert my whole project to component, so I have a bit of a bootstrapping problem.

potetm21:09:47

You should be able to mock things together pretty easily to see if you have everything hooked up. You can even stub to your local fs instead of s3 if you wanted to do a little io.

bhagany21:09:20

heh, that's actually my motivation. I want to be able to develop this locally without constantly deploying to lambda

potetm21:09:31

My only other thought was, have a go block that swaps into an atom when it’s done and store both the go-process chan and the atom on the record.

potetm21:09:51

Then you could block on the go-process, then, when it’s closed, read the atom.

potetm21:09:04

Not sure how I feel about that, but it is a thought I had.

bhagany21:09:08

hmm, that's interesting...

bhagany21:09:45

I'd have to check to see if the atom contains nil before every connection access, but that could be abstracted away

bhagany21:09:05

or if the channel is closed, as you said

potetm21:09:06

Well, you could just always just block on the chan first.

potetm21:09:12

That’s the sucky part, but you are doing async...

bhagany21:09:54

right. I wish there were a way to un-async node simple_smile

potetm21:09:57

Man… this is a good one. How do you start a component in an async environment?

potetm21:09:54

I bet you could get an answer from Stuart directly if you post in #C03S1KBA2.

bhagany21:09:32

I might yet… but I think I'll see if I can get something that runs first