'From etoys3.0 of 19 February 2008 [latest update: #2007] on 6 June 2008 at 7:16:49 pm'! "Change Set: fixSharedQueue-bf Date: 6 June 2008 Author: Bert Freudenberg Fix SharedQueue>>nextOrNilSuchThat: to not throw away non-matching elements."! !SharedQueue methodsFor: 'accessing' stamp: 'bf 6/6/2008 17:29'! nextOrNilSuchThat: aBlock "Answer the next object that satisfies aBlock, or nil otherwise. Leave other enqueued objects in place." | value i each | accessProtect critical: [ value := nil. i := readPosition. [i < writePosition] whileTrue: [ each := contentsArray at: i. (aBlock value: each) ifTrue: [ value := each. [i > readPosition] whileTrue: [ contentsArray at: i put: (contentsArray at: i-1). i := i - 1]. contentsArray at: readPosition put: nil. readPosition := readPosition + 1. readSynch wait. i := writePosition. ]. i := i + 1. ]. ]. ^value "=== | q c v | q := SharedQueue new. 1 to: 10 do: [ :i | q nextPut: i]. c := OrderedCollection new. [ v := q nextOrNilSuchThat: [ :e | e odd]. v notNil ] whileTrue: [ c add: {v. q size} ]. {c. q} ==="! !