Fork me on GitHub
#hyperfiddle
<
2023-11-03
>
henrik14:11:30

I’m working on our AI stuff now. I’ve wrapped our old AI infra, which returns a stream of messages in the form of maps, in an m/observe. I’m relieving this with a function that merges into a single message, if necessary. For the semantics of Electric, is this enough to ensure that I don’t lose messages? For example, let’s say I take those results (on the server) and merge into an atom (client side), will the atom eventually contain the complete state? The other alternative (that I can see) being that I could accumulate in an atom on the server, which I read from the client.

xificurC16:11:11

Generally electric runs in continuous time, i.e. you cannot rely on seeing all messages. If you show some code we can discuss more concretely. I think we will have a better answer in the next version of electric, which will operate on diffs and allow weaving in streams of data. To be seen. Accumulating on the server into an atom or db, in missionary discrete flows, and querying that from the client is guaranteed to work.

henrik16:11:27

Something like this

xificurC16:11:30

The latter is safer. I'd also consider moving the swap! inside the observe code, if it's running for side effects only it doesn't need to return values back to electric.

(new (m/observe (fn [!] (! nil) (swap! some-atom merge ..) #(cleanup))))
This will return nil on mount and never update, which is OK for side effects.

👍 1