Two posts in one day. In previous post I showed the first version of goroutines and channels in Rye. Now I joined them with websockets into a minimal chat example.
All Go chat examples were quite complex so I couldn't use them and I pretty much tried the simplest structure of channels, sockets, goroutines that made sense to me. And it worked. This could mean that Go channels are pretty intuitive and flexible tool.
The code works with restarts and disconnects. Rye's failure management with purge (inverse of HOF filter) worked quite nicely for cleaning up the closed sockets.
Now that all this message passing works, I would only need to add additional structure to messages, sockets and the hub. To add nicknames, enter - leave events, history, etc ...
Maybe I will discover I am using sockets wrong here as I better get to know Go's concurrency. Although it works I am not 100% sure if I can read and write to a websocket from two different goroutines. Maybe some syncing mechanism will be needed?
New standard functions
For this to work I also needed to add some standard functions. I created purge, switch, failed? and eval.
Eval is a very common Rebol function but there it is called reduce. When rebol was created map/reduce wasn't yet popular, now eval makes more sense I think. Eval in Javascript and Python evaluates the code, like do in Rebol and Rye does. Reduce evaluates a block of expresions into a block of values, so it sounds appropriate. Since this is one of most used words in Rye/Rebol the shorter eval vs evaluate makes sense.
Komentarji
Objavite komentar