SharedQueue>>#nextOrNil

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SharedQueue>>#nextOrNil

Lars Wassermann-2
Hello Squeak-dev,

SharedQueue>>#nextOrNil is deliberately implemented in such a way, that
it raises an error instead of returning nil, in case the Queue is empty.
>From the versions, it is obvious that this change was an 'improvement'.
Can anybody remember _why_ this change was done?

 From a discussion in Mantis I know that for new projects, one should
use SharedQueue2 instead. But I can't change to SharedQueue2 because the
receiver is DeferredUIMessages, a class variable of WorldState.

Thank you.
  - Lars

Reply | Threaded
Open this post in threaded view
|

Re: SharedQueue>>#nextOrNil

Bert Freudenberg
On 2013-05-28, at 12:04, Lars Wassermann <[hidden email]> wrote:

> Hello Squeak-dev,
>
> SharedQueue>>#nextOrNil is deliberately implemented in such a way, that it raises an error instead of returning nil, in case the Queue is empty.

No, I think you are misreading the code:

SharedQueue new nextOrNil
==> nil

SharedQueue new nextPut: 42; nextOrNil
==>  42

SharedQueue new nextPut: 42; nextOrNil; nextOrNil
==> nil


> From the versions, it is obvious that this change was an 'improvement'.
> Can anybody remember _why_ this change was done?

The error is merely there to alert you when the queue got into an inconsistent state.

- Bert -