[Opa] Network.channel

Adam Koprowski Adam.Koprowski at mlstate.com
Thu Aug 18 12:41:26 EDT 2011


  Dear Mads,

  Quick reply on the run:

   - I'm told that Network.cloud should work fine in `shared` mode (activate
   with --cloud argument to your app),
   - however, if will ignore they key argument for the non-shared (default)
   mode.

   The fix would be to maintain an association from keys to networks and use
the memorized one if present, instead of creating a new one. I'll try to
write this fix shortly, so it should hopefully make it into the nighties
within a couple of days. If you forget about thread-safety and other
trickery it should be few lines of code so you can try it yourself as an
exercise :) (i.e. a wrapper for Network.cloud that does memoization for
Networks). Will keep you updated.

  Adam

On Thu, Aug 18, 2011 at 16:35, Mads Jensen <mads379 at gmail.com> wrote:

> Hi Adam,
>
> Lets say you wanted to extend the Chat example with the possibility to
> create new
> named chat rooms. Once a user has created such a chat-room other users
> could
> join it and the messages would be broadcasted to everyone in that chatroom.
>
> Currently I have something like this but I don't know if I'm on the
> right track. At least
> the message_recieved function never seems to get executed.
>
> MyModule = {{
>
>        user_state = UserContext.make({none}: option(....))
>
>        get_state() = .....
>
>        create(name: string) =
>        (
>                 channel = Network.cloud(name): Network.network(message)
>                 do UserContext.change(( _ -> { some = { .. some info ..
> channel =
> channel }}), user_state)
>                do Client.goto("view/{name")
>        )
>
>        join(name: string, user: user ) =
>        (
>                 channel = Network.cloud(name): Network.network(message)
>                 do Network.broadcast({ joining = user},channel)
>                do UserContext.change(( _ -> { some = { .. some info ..
> channel =
> channel }}), user_state)
>                Client.goto("view/{name")
>        )
> }}
>
> @client when_ready(name,color): void = (
>        channel  = Option.get(MyModule.get_state()).channel
>        ...
>        do Network.observe(message_recieved, channel)
>        Board.prepare(Board.create())
> )
>
> @client message_recieved(msg: message) = ....
>
> // the function that is invoked when urls matching "view/{name}"
> view(name: string) =
> (
>        Resource.styled_page("Chess", style,
>                <div onready={_ -> when_ready(name,color) }>
>                        {Template.parse(Template.default,
> @static_content("resources/board.xmlt")()) |>
> Template.to_xhtml(Template.default, _)}
>                </div>
>        )
> )
>



-- 
*Adam Koprowski  [http://adam-koprowski.net]
R&D @ MLstate   [http://opalang.org | http://mlstate.com] *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.owasp.org/pipermail/opa/attachments/20110818/733d23a7/attachment.html 


More information about the Opa mailing list