[Seaside] Displaying progress on a web page
ramon.leon at allresnet.com
Thu Aug 17 15:48:39 UTC 2006
> -----Original Message-----
> From: seaside-bounces at lists.squeakfoundation.org
> [mailto:seaside-bounces at lists.squeakfoundation.org] On Behalf
> Of Mart-Mari Breedt
> Sent: Thursday, August 17, 2006 4:38 AM
> To: The Squeak Enterprise Aubergines Server - general discussion.
> Subject: RE: [Seaside] Displaying progress on a web page
> Thanks Philippe,
> I think fixing Comet is a little bit much for a relative
> newbie like myself to chew on :-), but I did try the
> periodical updates and I got the effect I desired. Was just
> wondering if there was another way to do this...
> About the script redirecting to the next page, do you maybe
> have an example of such a script? Or is there a way to stop
> the updates? I have this scenario now where the update just
> keeps on running even after no progress has been made on the
> client side.
> Thank you,
Try this, on your periodical, set a high decay rate, say 1000. This will
stop the polling if the same answer comes back twice. Then in the render
method, besides what you're already rendering, do something like this...
r hiddenInput text: r nextId
This will make each answer unique preventing the decay from kicking in.
When you want to stop polling, stop rendering the hidden value, and polling
will stop after the next hit.
I've added a couple small extension methods to WATagBrush that I have yet to
publish, but they seem to be working pretty well for me so far. I use
polling to fork off a long running process on another thread, then poll for
the result until it finishes or times out. No promises, but I'll share what
I use for now.
WATagBrush>>with: initialBlock waitMax: aDuration forWork: aBlock
self attributeAt: #default put: initialBlock value.
self with: initialBlock.
self waitMax: aDuration forWork: aBlock thenRender: aRenderBlock
WATagBrush>>waitMax: aDuration forWork: aBlock thenRender: aRenderBlock
"poll for results, stop when found or timeout expires"
| result |
result := self forkWaitFor: aDuration longRunningProcess: aBlock.
canvas script: ((canvas periodical)
id: (self attributes at: #id);
(result at: #result) ifNil:
[r text: (self attributeAt: #default).
r hiddenInput text: r nextId]
ifNotNil: [aRenderBlock value: r value: (result
WATagBrush>>forkWaitFor: aDuration longRunningProcess: aBlock
| startAt result |
result := (Dictionary new)
at: #result put: nil;
startAt := DateAndTime now.
[[[(result at: #result) isNil] whileTrue:
[DateAndTime now - startAt > aDuration ifTrue: [Error signal:
(Delay forMilliseconds: 100) wait.
result at: #result put: aBlock value]]
do: [:error | result at: #result put: error messageText]]
forkNamed: 'ajax async:'.
I use it like so...
with:[html text: 'Searching...']
waitMax: 30 seconds
forWork: [self getDataFromLongRunningProcess]
thenRender:[:r :value | r text: value]
More information about the Seaside