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

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

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
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44608 311
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

We're in Beta

About us Mission Statement