]> gitweb.factorcode.org Git - factor.git/blob - extra/models/conditional/conditional.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / extra / models / conditional / conditional.factor
1 ! Copyright (C) 2009 Sam Anklesaria.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays accessors kernel models threads calendar ;
4 IN: models.conditional
5
6 TUPLE: conditional < model condition thread ;
7
8 M: conditional model-changed
9     [
10         [ dup
11             [ condition>> call( -- ? ) ]
12             [ thread>> self = not ] bi or
13             [ [ value>> ] dip set-model f ]
14             [ 2drop t ] if 100 milliseconds sleep
15         ] 2curry "models.conditional" spawn-server
16     ] keep thread<< ;
17
18 : <conditional> ( condition -- model )
19     f conditional new-model swap >>condition ;
20
21 M: conditional model-activated [ model>> ] keep model-changed ;