boiserunner

boiserunner

Preload AsyncResult

Hi,

Is there a way to preload %AsyncResult{}? My UI is a chat widget where the messages are an array of messages wrapped inside AsyncResult.

When a user submits a new message, I want to make an optimistic update before I need to do some network and DB operations. In my handle_event, can I assign to the socket’s :messages my current messages ++ [new_message] before also running assign_async on the same key?

Thanks!

First Post!

boiserunner

boiserunner

After thinking about it more, it seems like I could do something like:

socket
|> assign(:messages, %AsyncResult{ok?: true, result: "Hello"})
|> assign_async(:messages, fn -> {:ok, %{messages: something_async()}} end)

Last Post!

christhekeele

christhekeele

One thing that I like about the new LV stream/stream_insert APIs is that they require each element to have an :id, which makes reasoning about these things easy: insert your optimistic render into the stream with an id immediately, and when the async result comes back with the same id, inserting it into the collection will replace the optimistic render. You might be able to extend that pattern to your assigns as well.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement