code-reviews

bhagany 2015-09-26T16:59:48.000013Z

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.

bhagany 2015-09-26T16:59:53.000014Z

Here's what I have: https://gist.github.com/4df04455e203992108b9

bhagany 2015-09-26T17:01:04.000015Z

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

bhagany 2015-09-26T17:02:24.000016Z

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.

danielcompton 2015-09-26T19:32:42.000017Z

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

danielcompton 2015-09-26T19:32:52.000018Z

I think that could be a go block

danielcompton 2015-09-26T19:33:18.000019Z

It doesn’t seem like it ever recurs?

bhagany 2015-09-26T19:33:39.000020Z

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

bhagany 2015-09-26T19:33:50.000021Z

ah, I did forget to recur

bhagany 2015-09-26T19:35:35.000022Z

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

danielcompton 2015-09-26T19:36:01.000023Z

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

bhagany 2015-09-26T19:37:01.000024Z

go-loop itself doesn't return a channel?

bhagany 2015-09-26T19:38:23.000025Z

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

bhagany 2015-09-26T19:40:05.000026Z

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

bhagany 2015-09-26T19:40:33.000027Z

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

bhagany 2015-09-26T19:52:39.000028Z

@danielcompton: updated the gist with a new attempt

danielcompton 2015-09-26T19:56:24.000029Z

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

bhagany 2015-09-26T19:56:35.000030Z

no problem, thanks for taking a look :simple_smile:

2015-09-26T20:40:04.000032Z

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

2015-09-26T20:40:33.000033Z

And you want it to block while you do that?

bhagany 2015-09-26T20:40:38.000034Z

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

bhagany 2015-09-26T20:40:53.000035Z

otherwise return a channel that constantly gives me the same connection

2015-09-26T20:43:55.000036Z

hmm… that’s a toughie

bhagany 2015-09-26T20:55:50.000037Z

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.

2015-09-26T21:02:47.000038Z

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.

bhagany 2015-09-26T21:03:20.000039Z

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

2015-09-26T21:03:31.000040Z

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.

2015-09-26T21:03:51.000041Z

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

2015-09-26T21:04:04.000042Z

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

bhagany 2015-09-26T21:04:08.000043Z

hmm, that's interesting...

bhagany 2015-09-26T21:04:45.000044Z

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

bhagany 2015-09-26T21:05:05.000045Z

or if the channel is closed, as you said

2015-09-26T21:05:06.000046Z

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

2015-09-26T21:05:07.000047Z

yeah

2015-09-26T21:05:12.000048Z

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

bhagany 2015-09-26T21:05:54.000050Z

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

2015-09-26T21:13:57.000051Z

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

2015-09-26T21:14:54.000052Z

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

bhagany 2015-09-26T21:25:32.000053Z

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

2015-09-26T21:29:28.000054Z

good plan