on 02422bc help sign in
86 lines 2.8 kB history raw
1+++
2title = "Reference"
3weight = 50
4template = "doc.html"
5+++
7## Spider
9- [Start a thread](#start-thread)
10- [Stop a thread](#stop-thread)
11- [Subscribe to thread result](#subscribe-to-thread-result)
12- [Subscribe to thread](#subscribe-to-thread)
13- [Poke a thread](#poke-thread)
15### Start thread
17Poke `spider` with mark `%spider-start` and a vase containing `start-args`:
19```hoon
20+$ start-args
21 [parent=(unit tid) use=(unit tid) file=term =vase]
22```
24Where:
26- `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.
27- `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.
28- `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`.
29- `vase` - `vase` to be given to the thread when it's started. Can be whatever or just `!>(~)` if it doesn't need any args.
31#### Example
33```hoon
34[%pass /some-path %agent [our.bowl %spider] %poke %spider-start !>([~ `tid %foo !>(~)])]
35```
37### Stop thread
39Poke `spider` with mark `%spider-stop` and a vase containing `[tid ?]`, where:
41- `tid` - the `tid` of the thread you want to stop
42- `?` - 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 `~`.
44#### Example
46```hoon
47[%pass /some-path %agent [our.bowl %spider] %poke %spider-stop !>([tid %.y)]
48```
50### Subscribe to thread result
52Spider will send the result on `/thread-result/[tid]` so you can subscribe there for the result. You should subscribe before starting the thread.
54The result will have a mark of either `%thread-fail` or `%thread-done`.
56- `%thread-fail` - has a vase containing a `[term tang]` where `term` is an error message and `tang` is a traceback.
57- `%thread-done` - has a vase of the result of the thread.
59#### Example
61```hoon
62[%pass /some-path %agent [our.bowl %spider] %watch /thread-result/[tid]]
63```
65### Subscribe to thread
67You 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.
69#### Example
71```hoon
72[%pass /some-path %agent [our.bowl %spider] %watch /thread/[tid]/thread-path]
73```
75### Poke Thread
77To poke a thread you poke spider with a mark of `%spider-input` and a vase of `[tid cage]`.
79- `tid` is the tid of the thread you want to poke
80- `cage` is whatever mark and vase you want to poke it with
82#### Example
84```hoon
85[%pass /some-path %agent [our.bowl %spider] %poke %spider-input !>([tid %foo !>('foooo')])]
86```