Web Frameworks
Avi Bryant
squeak-dev at lists.squeakfoundation.org
Tue Sep 3 16:30:56 UTC 2002
Stephen Pair wrote:
> How are continuations implemented? Can you cope with the use of the
> back button in the browser with continuations?
> I do exactly the same thing as continuations in Swiki.net. They are
> much nicer to work with. I implemented it by copying the Squeak context
> stack at each reply-request interaction. If the browser's back button
> is used, I just schedule a new Squeak Process on a saved copy of the
> stack as it existed at the previous reply-request interaction.
Yes, that's also how Seaside works. I also include a
transaction mechanism which lets you control for how long the back button
will actually work; if you write
session isolate:
[self page1.
self page2.
self page3].
self page4.
Then you can use the back button to make the call to #page1 return as many
times as you want until you hit page 4; at that point any attempt to
interact with pages 1 to 3 will just redirect you back to your current
page.
The kernel of Seaside 2.0 provides a nice abstraction for anyone who wants
to play with the idea of continuation-based sessions without committing to
Seaside or Swiki.net in their entirety; using it looks like this:
WAApplication named: 'myapp' do:
[:session | |request|
request := session respond:
[:response |
response nextPutAll: ... ].
...
request := session respond:
[:response |
... ]]
Which is to say:
- When someone hits the 'myapp' URL, a new session object is created and
passed into the block.
- When you call #respond: on this session object, a response object is
created and passed into the response block. Use the response object like
a stream to create a page.
- Whenever somebody clicks a link or submits a form from that page, that
call to #respond: will return a request object with the query
parameters or form data, and the session block will continue running from
that point. This can happen more than once for a single call to
#respond: (think back button).
This is at a way lower level than I would ever use directly, but I think
it's a good way to wrap your head around this style of development for
those coming from CGI or servlet backgrounds.
Cheers,
Avi
More information about the Squeak-dev
mailing list
|