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.
Here's what I have: https://gist.github.com/4df04455e203992108b9
I started out really wanting to assoc the conn
atom into the component, but I think I have to be content with the channel.
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.
@bhagany: what’s the benefit of creating a go-loop?
I think that could be a go block
It doesn’t seem like it ever recurs?
@danielcompton: I want to be able to take from conn-ch
multiple times, and get the same conn
back
ah, I did forget to recur
I am not entirely certain this will work the way I envision - never used a go-loop
before
I think you’ll need to return a channel if you want the go-loop to keep running
go-loop
itself doesn't return a channel?
hmmm, but there's nothing that parks it if conn
exists...
and I believe I'm trying to treat the record as a mutable thing. so this doesn't work on multiple levels.
but, that leaves me with very little idea about how to create a component out of something with an async start
@danielcompton: updated the gist with a new attempt
I don’t know enough about component to comment much further sorry
no problem, thanks for taking a look :simple_smile:
@bhagany: Let me get this straight. You want to initialize the db (aka conn in datascript) in that start
fn?
And you want it to block while you do that?
@potetm: yes, that's right, if it's possible
otherwise return a channel that constantly gives me the same connection
hmm… that’s a toughie
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.
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.
heh, that's actually my motivation. I want to be able to develop this locally without constantly deploying to lambda
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.
Then you could block on the go-process, then, when it’s closed, read the atom.
Not sure how I feel about that, but it is a thought I had.
hmm, that's interesting...
I'd have to check to see if the atom contains nil before every connection access, but that could be abstracted away
or if the channel is closed, as you said
Well, you could just always just block on the chan first.
yeah
That’s the sucky part, but you are doing async...
right. I wish there were a way to un-async node :simple_smile:
Man… this is a good one. How do you start a component in an async environment?
I bet you could get an answer from Stuart directly if you post in #C03S1KBA2.
I might yet… but I think I'll see if I can get something that runs first
good plan