@@ -4,31 +4,31 @@ weight = 2
44template = "doc.html"
55+++
66
7−Here's a simple example of a thread that starts another thread:
7+Here's a simple example of a thread that starts another thread:
88
9−### parent.hoon
9+#### `parent.hoon`
1010
1111```hoon
1212/- spider
1313/+ *strandio
1414=, strand=strand:spider
15−^- thread:spider
16−|= arg=vase
17−=/ m (strand ,vase)
15+^- thread:spider
16+|= arg=vase
17+=/ m (strand ,vase)
1818^- form:m
1919;< tid=tid:spider bind:m (start-thread %child)
2020(pure:m !>(~))
2121```
2222
23−### child.hoon
23+#### `child.hoon`
2424
2525```hoon
2626/- spider
2727/+ *strandio
2828=, strand=strand:spider
29−^- thread:spider
30−|= arg=vase
31−=/ m (strand ,vase)
29+^- thread:spider
30+|= arg=vase
31+=/ m (strand ,vase)
3232^- form:m
3333%- (slog leaf+"foo" ~)
3434(pure:m !>(~))
@@ -48,7 +48,7 @@ foo
4848;< tid=tid:spider bind:m (start-thread %child)
4949```
5050
51−See here how we gave `start-thread` the name of the thread to run. It returns the `tid` of the thread, which we could then use to poke it or whatever.
51+See here how we gave `start-thread` the name of the thread to run. It returns the `tid` of the thread, which we could then use to poke it or whatever.
5252
5353`start-thread` handles creating the `tid` for the thread so is quite convenient.
5454
@@ -58,15 +58,15 @@ Note that threads we start this way will be a child of the thread that started t
5858
5959If we want to actually get the result of the thread we started, it's slightly more complicated:
6060
61−### parent.hoon
61+#### `parent.hoon`
6262
6363```hoon
6464/- spider
6565/+ *strandio
6666=, strand=strand:spider
67−^- thread:spider
68−|= arg=vase
69−=/ m (strand ,vase)
67+^- thread:spider
68+|= arg=vase
69+=/ m (strand ,vase)
7070^- form:m
7171;< =bowl:spider bind:m get-bowl
7272=/ tid `@ta`(cat 3 'strand_' (scot %uv (sham %child eny.bowl)))
@@ -84,7 +84,7 @@ If we want to actually get the result of the thread we started, it's slightly mo
8484==
8585```
8686
87−### child.hoon
87+#### `child.hoon`
8888
8989```hoon
9090/- spider
@@ -94,9 +94,9 @@ If we want to actually get the result of the thread we started, it's slightly mo
9494|%
9595++ url "https://www.whatsthelatestbasehash.com/"
9696--
97−^- thread:spider
98−|= arg=vase
99−=/ m (strand ,vase)
97+^- thread:spider
98+|= arg=vase
99+=/ m (strand ,vase)
100100^- form:m
101101;< =cord bind:m (fetch-cord url)
102102=/ hash-as-cord `@t`(end [3 (sub (met 3 cord) 1)] cord)
@@ -104,7 +104,7 @@ If we want to actually get the result of the thread we started, it's slightly mo
104104(pure:m !>(hash))
105105```
106106
107−`child.hoon` simply grabs the latest base hash from https://www.whatsthelatestbasehash.com/ and returns it.
107+`child.hoon` simply grabs the latest base hash from https://www.whatsthelatestbasehash.com/ and returns it.
108108
109109`parent.hoon` is a bit more complicated so we'll look at it line-by-line
110110
@@ -136,10 +136,10 @@ We pre-emptively subscribe for the result. Spider sends the result at `/thread-r
136136
137137Spider takes a poke with a mark %spider-start and a vase containing `[parent=(unit tid) use=(unit tid) file=term =vase]` to start a thread, where:
138138
139−* `parent` is an optional parent thread. In this case we say the parent is our tid. Specifying a parent means the child will be killed if the parent ends.
140−* `use` is the thread ID for the thread we're creating
141−* `file` is the filename of the thread we want to start
142−* `vase` is the vase it will be given as an argument when it's started
139+- `parent` is an optional parent thread. In this case we say the parent is our tid. Specifying a parent means the child will be killed if the parent ends.
140+- `use` is the thread ID for the thread we're creating
141+- `file` is the filename of the thread we want to start
142+- `vase` is the vase it will be given as an argument when it's started
143143
144144```hoon
145145;< =cage bind:m (take-fact /awaiting/[tid])
@@ -164,15 +164,15 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
164164
165165## Stop a thread
166166
167−### parent.hoon
167+#### `parent.hoon`
168168
169169```hoon
170170/- spider
171171/+ *strandio
172172=, strand=strand:spider
173−^- thread:spider
174−|= arg=vase
175−=/ m (strand ,vase)
173+^- thread:spider
174+|= arg=vase
175+=/ m (strand ,vase)
176176^- form:m
177177;< =bowl:spider bind:m get-bowl
178178=/ tid `@ta`(cat 3 'strand_' (scot %uv (sham %child eny.bowl)))
@@ -193,7 +193,7 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
193193(pure:m !>("Done"))
194194```
195195
196−### child.hoon
196+#### `child.hoon`
197197
198198```hoon
199199/- spider
@@ -213,8 +213,8 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
213213 ==
214214--
215215^- thread:spider
216−|= arg=vase
217−=/ m (strand ,vase)
216+|= arg=vase
217+=/ m (strand ,vase)
218218^- form:m
219219;< ~ bind:m looper
220220(pure:m !>(~))
@@ -232,6 +232,6 @@ Finally we test whether the thread produced a `%thread-done` or a `%thread-fail`
232232 ==
233233```
234234
235−* `%spider-stop` is the mark that tells spider to kill a thread.
236−* `tid` is the tid of the thread to kill
237−* `%.y` tells spider to suppress traceback in the result of the killed thread. If you give it `%.n` it will include the traceback.
235+- `%spider-stop` is the mark that tells spider to kill a thread.
236+- `tid` is the tid of the thread to kill
237+- `%.y` tells spider to suppress traceback in the result of the killed thread. If you give it `%.n` it will include the traceback.