]> gitweb.factorcode.org Git - factor.git/blob - basis/concurrency/promises/promises-docs.factor
9760d842dca97ccbc9f81e7b6e879b37d99f2d98
[factor.git] / basis / concurrency / promises / promises-docs.factor
1 ! Copyright (C) 2005, 2008 Chris Double, Slava Pestov.\r
2 ! See http://factorcode.org/license.txt for BSD license.\r
3 USING: calendar help.markup help.syntax kernel ;\r
4 IN: concurrency.promises\r
5 \r
6 HELP: promise\r
7 { $class-description "The class of write-once promises." } ;\r
8 \r
9 HELP: <promise>\r
10 { $values { "promise" promise } }\r
11 { $description "Creates a new promise which may be fulfilled by calling " { $link fulfill } "." } ;\r
12 \r
13 HELP: promise-fulfilled?\r
14 { $values { "promise" promise } { "?" boolean } }\r
15 { $description "Tests if " { $link fulfill } " has previously been called on the promise, in which case " { $link ?promise } " will return immediately without blocking." } ;\r
16 \r
17 HELP: ?promise-timeout\r
18 { $values { "promise" promise } { "timeout" { $maybe duration } } { "result" object } }\r
19 { $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled. A timeout of " { $link f } " indicates that the thread may block indefinitely, otherwise it will wait up to the " { $snippet "timeout" } " before throwing an error." }\r
20 { $errors "Throws an error if the timeout expires before the promise has been fulfilled." } ;\r
21 \r
22 HELP: ?promise\r
23 { $values { "promise" promise } { "result" object } }\r
24 { $description "Waits for another thread to fulfill a promise, returning immediately if the promise has already been fulfilled." } ;\r
25 \r
26 HELP: fulfill\r
27 { $values { "value" object } { "promise" promise } }\r
28 { $description "Fulfills a promise by writing a value to it. Any threads waiting for the value are notified." }\r
29 { $errors "Throws an error if the promise has already been fulfilled." } ;\r
30 \r
31 ARTICLE: "concurrency.promises" "Promises"\r
32 "The " { $vocab-link "concurrency.promises" } " vocabulary implements " { $emphasis "promises" } ", which are thread-safe write-once variables. Once a promise is created, threads may block waiting for it to be " { $emphasis "fulfilled" } "; at some point in the future, another thread may provide a value at which point all waiting threads are notified."\r
33 { $subsections\r
34     promise\r
35     <promise>\r
36     fulfill\r
37     ?promise\r
38     ?promise-timeout\r
39 } ;\r
40 \r
41 ABOUT: "concurrency.promises"\r