As you can see the primary usage pattern looks like this
for( msg <- rabbitMonadically.beginService() ) {
// msg handling code goes here
...
}
To me this is very intuitive. We are iterating over a stream of messages and handling them in the code body of the "for-loop". All the threading and state management that supports this view is safely tucked away behind this interface.
Oleg Kiselyov has been the most eloquent proponent of this idea, and i cannot hope to match the elegance of his code or his prose. However, it's still a great deal of fun to do something for yourself to test your understanding. So, let's implement this design pattern in Scala over RabbitMQ.
It turns out that Tiark Rompf has already done most of the work for us in one of the test suites for delimited continuations! He did it for a stream of HTTP requests; so, his job was actually a little bit harder because he had to deal with TCP/IP socket requests as well. We just crib his code and modify it to suit our purposes. Likewise, i've been cribbing from and comparing with the Lift actor-based API to RabbitMQ. i leave it to you to do the comparison in terms of understandability.
BTW, if you'd like to see more of this -- and in nice book format to boot! -- then please consider making a pledge to the Kickstarter project for the Monadic Design Patterns for the Web book.
|
|
1 comment:
Cool.... Unfortunately continuations is a little hard for me.
But sounds very interesting. Thanks.
Post a Comment