We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Sending Structs in GenServer Calls
59
clicks
Source: reddit.com
The author, mucho_mass, is experimenting with GenServer to create a key-value store in Elixir. They have created a custom struct `FormatFile` and want to use an atom, `:put`, alongside this struct to communicate with GenServer. However, they're facing a syntax error when trying to use `GenServer.cast(server, %FormatFile{:put, timestamp, key, value})`. Other users, ScrimpyCat and bmitc, suggest that the correct approach is to pass the atom and the struct within a tuple, and the correct form of the struct should be `%FormatFile{timestamp: some_timestamp, key: key, value: value}`. Thanks to the community's help, mucho_mass understands the proper syntax for sending the command and struct data together to GenServer.
Related posts
© HashMerge 2024