[Seaside] Task Escape

Philippe Marschall philippe.marschall at gmail.com
Wed Jan 9 22:02:38 UTC 2008


2008/1/9, Zulq Alam <me at zulq.net>:
> I have a task with N steps:
>
> MyTask>>#go
>         self stepOne.
>         self stepTwo.
>         ...
>         self stepN.
>
> Each step calls one or more components. Each component offer a Cancel
> link / button. If clicked, the component answers false. If a component
> answers false, the task should stop. I currently do this by checking the
> answer value and then answering if the value is false.
>
> MyTask>>#stepN
>         (self call: MyComponent new)
>                 ifFalse: [self answer: false]
>
> This seems to work OK but only if the task has been called. If it is the
> root component, then the answer is a no-op.

Right but, instead of #answer: ing you could as well #call: something like:

MyTask>>#stepN
        (self call: MyComponent new)
                ifFalse: [ self call: CanceledComponent new ]

It's probably best to encapsulate such logic in an own method:

MyTask>>#done
        self call: CanceledComponent new

MyTask>>#stepN
        (self call: MyComponent new)
                ifFalse: [ self done ]

> I don't intend for such tasks to be used as root components and
> practically this isn't a problem but it doesn't feel right. The task
> should work no matter how it is being used.
>
> I suppose I could check after each step (yuk):
>
> MyTask>>#go
>         ((self stepOne
>                 ifTrue: [self stepTwo])
>                         ifTrue: [self stepThree])
>         ...
>                         ifTrue: [self stepN]
>
> Or, I could check at the beginning of each step (*slightly* less yuk):
>
> MyTask>>#stepN
>         shouldRun ifFalse: [^ self].
>         ...
>
> Or:
>
> MyTask>>#stepN
>         self stepNMinusOne ifFalse: [^ self]
>         ...
>
> Or I could use a signal:
>
> MyTask>>#stepN
>         (self call: MyComponent new) ifFalse: [MyCancellation signal]
>
> MyTask>>#go
>         [self stepOne.
>         self stepTwo.
>         ...
>         self stepThree]
>                 on: MyCancellation
>                 do: [self answer: false]
>
> To me the signal looks the best, but feels like an abuse of the
> exception handling framework.
>
> What have others done? It's very possible I still don't know how to use
> tasks properly, so please feel free to correct me!

I agree (on everything else) and no, this doesn't have to do with your
task knowledge. Something you could use is announcements [1] to signal
cancelation right in your components (that you call in the steps) and
handle that only in one place so you don't have to check their return
value. As usual, pay attention to your subscribers to prevent "memory
leaks".

[1] http://onsmalltalk.com/programming/smalltalk/maintaining-loose-coupling-in-seaside-components/


Cheers
Philippe


More information about the seaside mailing list