]> gitweb.factorcode.org Git - factor.git/blob - basis/io/timeouts/timeouts-docs.factor
626f0c24c092bb3c308fdf0eff368cb3127a996d
[factor.git] / basis / io / timeouts / timeouts-docs.factor
1 IN: io.timeouts\r
2 USING: help.markup help.syntax math kernel calendar ;\r
3 \r
4 HELP: timeout\r
5 { $values { "obj" object } { "dt/f" { $maybe duration } } }\r
6 { $contract "Outputs an object's timeout." } ;\r
7 \r
8 HELP: set-timeout\r
9 { $values { "dt/f" { $maybe duration } } { "obj" object } }\r
10 { $contract "Sets an object's timeout." }\r
11 { $examples "Waits five seconds for a process that sleeps for ten seconds:"\r
12   { $unchecked-example\r
13     "USING: calendar io.launcher io.timeouts kernel ;"\r
14     "\"sleep 10\" >process 5 seconds over set-timeout run-process"\r
15     "Process was killed as a result of a call to"\r
16     "kill-process, or a timeout"\r
17   }\r
18 } ;\r
19 \r
20 HELP: cancel-operation\r
21 { $values { "obj" object } }\r
22 { $contract "Handles a timeout, usually by waking up all threads waiting on the object." } ;\r
23 \r
24 HELP: with-timeout\r
25 { $values { "obj" object } { "quot" { $quotation ( obj -- ) } } }\r
26 { $description "Applies the quotation to the object. If the object's timeout expires before the quotation returns, " { $link cancel-operation } " is called on the object." } ;\r
27 \r
28 ARTICLE: "io.timeouts" "I/O timeout protocol"\r
29 "Streams, processes and monitors support optional timeouts, which impose an upper bound on the length of time for which an operation on these objects can block. Timeouts are used in network servers to prevent malicious clients from holding onto connections forever, and to ensure that runaway processes get killed."\r
30 { $subsections\r
31     timeout\r
32     set-timeout\r
33 }\r
34 "The I/O timeout protocol can be implemented by any class wishing to support timeouts on blocking operations."\r
35 { $subsections cancel-operation }\r
36 "A combinator to be used in operations which can time out:"\r
37 { $subsections with-timeout }\r
38 { $see-also "stream-protocol" "io.launcher" "io.monitors" } ;\r
39 \r
40 ABOUT: "io.timeouts"\r