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 :)


-- 

Cyril Ferlicot

http://www.synectique.eu

165 Avenue Bretagne
Lille 59000 France

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to