Prev | Current Page 44 | Next

Brad Ediger

"Advanced Rails"

Each user session corresponds
to a server-side continuation. When a request comes in, the continuation is
invoked and more code is run. The upshot is that entire transactions can be written
as a single stream of code, even if they span multiple HTTPrequests. This power
comes from the fact that Smalltalk??™s continuations are serializable; they can be written
out to a database or to the filesystem, then thawed and reinvoked upon a request.
Ruby??™s continuations are nonserializable. In Ruby, continuations are in-memory only
and cannot be transformed into a byte stream.
Borges (http://borges.rubyforge.org/) is a straightforward port of Seaside 2 to Ruby.
The major difference between Seaside and Borges is that Borges must store all current
continuations in memory, as they are not serializable. This is a huge limitation
that unfortunately prevents Borges from being successful for web applications with
any kind of volume. If serializable continuations are implemented in one of the Ruby
implementations, this limitation can be removed.
The power of continuations is evident in the following Borges sample code, which
renders a list of items from an online store:
class SushiNet::StoreItemList < Borges::Component
def choose(item)
call SushiNet::StoreItemView.new(item)
end
* http://seaside.st/
Metaprogramming Techniques | 27
def initialize(items)
@batcher = Borges::BatchedList.


Pages:
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56