This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
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
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
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
@bhagany: Let me get this straight. You want to initialize the db (aka conn in datascript) in that start
fn?
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.