Vault - a lightweight process-scoped global data storage with immutability guarantees

Correct, in the example you’ve provided you’re linking the processes after initializing the vault, and because of that it’s not working. But I think not using links will eliminate this problem entirely.

Yeah, you’re right, this is a wrong argument for Registry, but this argument applies to my point about $ancestors and $caller

Yep, will apply this, thanks!

Sure, but you already have the API to change the value, which only works for the current process. I only suggested to improve this situation. In the end of the day, any approach can be made immutable by removing the function to update the data :grin:

It’s prefixed with unsafe_*, so it’s unsafe :person_shrugging: and I think we should be fine with not placing any expectations there? I’m open to any alternatives though

Tests, like common use case of Mox’s allow . Process pools. Or I use a library which just spawns a process without link and I want to share the state with it. Not all processes links form a tree, although that’s the best approach to do it imo.

I think using $ancestors + $callers + :erlang.process_info(self(), :parent) as a list of associated processes should resolve this issue and you’ll be able to initialize the state inside a setup block.

I understand it now. Sounds like a use-case for Logger.metadata

Not really, I want to persist these audit logs in the database instead of flushing to some external system. Also, it’s not only applying to audit logging, there are a ton of places you need to refer to user (setting user-related columns in the db, which represent the actor of the action), verifying permissions closer to the context, and many, many more. Plus, it doesn’t need to be user, it can be a broader context where you put whatever you like. You just need to guarantee that it’s not changing across the request (or the changes of these entities do not impact the lifecycle of your process).

1 Like