on 55f30ca help sign in
78 lines 2.6 kB history raw
1+++
2title = "Reference"
3weight = 50
4template = "doc.html"
5+++
7## Start thread
9Poke `spider` with mark `%spider-start` and a vase containing `start-args`:
11```hoon
12+$ start-args
13 [parent=(unit tid) use=(unit tid) file=term =vase]
14```
16Where:
18- `parent` - optional `tid` of parent thread if the thread is a child. If specified, the child thread will be killed with the parent thread ends.
19- `use` - `tid` (thread ID) to give the new thread. Can be generated with something like `(scot %ta (cat 3 'my-agent_' (scot %uv (sham eny))))`. However you do it, make sure it's unique.
20- `file` - name of the thread file in `/ted`. For example, if the thread you want to start is `/ted/foo/hoon` you'd specify `%foo`.
21- `vase` - `vase` to be given to the thread when it's started. Can be whatever or just `!>(~)` if it doesn't need any args.
23#### Example
25```hoon
26[%pass /some-path %agent [our.bowl %spider] %poke %spider-start !>([~ `tid %foo !>(~)])]
27```
29## Stop thread
31Poke `spider` with mark `%spider-stop` and a vase containing `[tid ?]`, where:
33- `tid` - the `tid` of the thread you want to stop
34- `?` - whether thread should end nicely. If `%.y` it'll end with mark `%thread-done` and the bunt value of a vase. If `%.n` it'll end with mark `%thread-fail` and a `[term tang]` where `term` is `%cancelled` and `tang` is `~`.
36#### Example
38```hoon
39[%pass /some-path %agent [our.bowl %spider] %poke %spider-stop !>([tid %.y)]
40```
42## Subscribe for result
44Spider will send the result on `/thread-result/[tid]` so you can subscribe there for the result. You should subscribe before starting the thread.
46The result will have a mark of either `%thread-fail` or `%thread-done`.
48- `%thread-fail` - has a vase containing a `[term tang]` where `term` is an error message and `tang` is a traceback.
49- `%thread-done` - has a vase of the result of the thread.
51#### Example
53```hoon
54[%pass /some-path %agent [our.bowl %spider] %watch /thread-result/[tid]]
55```
57## Subscribe to thread
59You can subscribe to a thread on `/thread/[tid]/path`. Note this is for facts sent off by the thread while it's running, not the final result. The path depends on the particular thread.
61#### Example
63```hoon
64[%pass /some-path %agent [our.bowl %spider] %watch /thread/[tid]/thread-path]
65```
67## Poke thread
69To poke a thread you poke spider with a mark of `%spider-input` and a vase of `[tid cage]`.
71- `tid` is the tid of the thread you want to poke
72- `cage` is whatever mark and vase you want to poke it with
74#### Example
76```hoon
77[%pass /some-path %agent [our.bowl %spider] %poke %spider-input !>([tid %foo !>('foooo')])]
78```