|
Re: ANNOUNCE ex11 release two: msg#00269lang.erlang.general
Joe Armstrong <joe@xxxxxxx> wrote: > I have experimented with many different styles of callback handling > and IMHO this is the best. If you want to do it with messages you can write > your top-level thing like this: > > B = swButton:make(Win ......) > S = self(), > B ! {onClick, fun(X) -> S ! {wrapper, X} end}, > ... > > loop(...). > > > loop(...) -> > receive > {wrapper, X} -> > Do something > ... > end What about allowing the caller to use a term for the message if they just want a message sent: B = swButton:make(Win ....), S = self(), B ! {onClick, {S, wrapper} end}, loop () -> receive {wrapper, X} -> end, loop(). Easy to tell a tuple and a fun apart; if it is a tuple it is a two tuple of {Pid, Tag}; which results in the message {Tag, X} being sent to to Pid. This way the caller doesn't need to build a fun, and waste all the bytecode and memory on a fun to just send itself a tagged message. Of course, this is only really useful if a large number of apps are written this way. :) -- Shawn. Getting there is only half as far as getting there and back. |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: How do I find my own IP address?: 00269, Miguel Barreiro |
|---|---|
| Next by Date: | Re: How do I find my own IP address?: 00269, Matthias Lang |
| Previous by Thread: | Re: [ex11] use of Displayi: 00269, Vlad Dumitrescu |
| Next by Thread: | Re: ANNOUNCE ex11 release two: 00269, Joe Armstrong |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |