1 ! Copyright (C) 2008 Slava Pestov, Doug Coleman
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors fry io io.encodings io.streams.null kernel
7 GENERIC: timeout ( obj -- dt/f )
8 GENERIC: set-timeout ( dt/f obj -- )
10 M: decoder set-timeout stream>> set-timeout ;
12 M: encoder set-timeout stream>> set-timeout ;
14 GENERIC: cancel-operation ( obj -- )
16 : queue-timeout ( obj timeout -- timer )
17 [ '[ _ cancel-operation ] ] dip later ;
19 : with-timeout* ( obj timeout quot -- )
20 2over queue-timeout [ nip call ] dip stop-timer ;
23 : with-timeout ( obj quot -- )
24 over timeout [ [ dup timeout ] dip with-timeout* ] [ call ] if ;
28 [ input-stream get set-timeout ]
29 [ output-stream get set-timeout ] bi ;
31 M: null-stream set-timeout 2drop ;