Two quick consecutive calls to wf:insert_bottom end up in the reverse order

1 view
Skip to first unread message

J. Pablo Fernández

unread,
Jan 4, 2010, 4:51:32 PM1/4/10
to Nitrogen Web Framework for Erlang
I have the following method that receives messages and adds them to
the bottom of an html element:

receive_messages() ->
receive
Message ->
io:format("~p received ~p", [self(), Message]),
wf:insert_bottom(messages, [#p{}, #span { text=io_lib:format
("~p", [Message]) }])
end,
wf:comet_flush(),
receive_messages().

It is set as the usual way for comet:

wf:comet(fun() -> receive_messages() end)

It receives two messages very quickly:

<0.907.0> received {starting_chat,<0.905.0>}
<0.907.0> received {connected_to,<0.902.0>}

This is what I see in the HTML:

{connected_to, <0.902.0>}
{starting_chat, <0.905.0>}

Somehow, they ended in the reverse order.

I've started adding timer:sleep() calls to this method. With 50
milliseconds, they are in the correct order, with 20 they are not.
When they are in the incorrect order they seem to be always in the
incorrect order, it seems very deterministic.

Any ideas why? Is this a bug? Any ideas what should I do to get them
in the correct order other than sleeping?

You can answer it on Stack Overflow if you want karma:
http://stackoverflow.com/questions/2002487/two-quick-consecutive-calls-to-wfinsertbottom-end-up-in-the-reverse-order

Tristan Sloughter

unread,
Jan 4, 2010, 4:59:30 PM1/4/10
to nitro...@googlegroups.com
There is a 'reverse' call to the list of comet events that if you remove fix this. Its:

collect_content() -> lists:reverse(inner_collect_content()).

in wf_comet.erl.

Not sure why it reverses it, but for a project I worked on I just removed it to fix that :). Maybe someone else has a better solution.

Tristan

2010/1/4 J. Pablo Fernández <pup...@pupeno.com>

--

You received this message because you are subscribed to the Google Groups "Nitrogen Web Framework for Erlang" group.
To post to this group, send email to nitro...@googlegroups.com.
To unsubscribe from this group, send email to nitrogenweb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nitrogenweb?hl=en.



Reply all
Reply to author
Forward
0 new messages