On 14 Oct 2015, at 1:32 , Ferlicot D. Cyril <cyril.ferlicot@gmail.com> wrote:

Le 14/10/2015 09:01, Henrik Johansen a ��crit :
If you by some chance don't like UILoops, and so don't want to make a spinning UILoop inside your UILoop, you could also use a single background thread, something like;

FilteredDataSource (to be used as dataSource for FastTable, polymorphic api to normal dataSource but redirecting to filteredDataSource variable)
class protocol
filter: aFilter source: aDataSource
^self new initializeFilter: aFilter source: aDataSource
inst protocol, update related
initializeFilter: aFilterField source: aDataSource

initialDataSource := filteredDataSource := aDataSource
filterChangeSemaphore := Semaphore new.
self spawnFilterUpdateThread
aFilterField when: ValueChanged send: #updateFilter: to self

updateFilter: aChangeAnnouncement
"(Probably) runs on UI thread"
pattern := aChangeAnnouncement newValue.
filterChangeSemaphore signal.

spawnFilterUpdateThread
"Runs in background"
[ | oldPattern |
oldPattern := pattern.
[ filterChangeSemaphore wait.
"If pattern has changed, see if we need to filter.
If not, it's probably an extraneous signal received while we were waiting for 0.2 seconds, and we discard then till we end up waiting for filterChangeSemaphore again"
oldPattern ~= pattern
ifTrue: [
oldPattern := pattern.
0.2 seconds wait.
"Pattern still the same? If not, just loop again and end up waiting for another 0.2 secs"
oldPattern = pattern
ifTrue: [
filteredDataSource := initialDataSource newDataSourceMatching: pattern.
self announce: WhateverChangeAnnouncementBasedOnWhichFastTableSchedulesAViewUpdateForItsDatasource ]]] repeat ]
forkAt: Processor userBackgroundPriority

Cheers,
Henry


Thank you really much!
I tried to get a working version of the widget with the UILoop but that
was terrible.
But the semaphore work fine. I still need to learn a lot of things about
fork, semaphore & co.

Thank you for your precious help :)

No problem!
I also tried to show how to avoid the FilteredDataSource model referencing GUI elements directly, hope you picked up on that as well :)

Cheers,
Henry