7Here's an example of a barebones gall agent that just starts a thread:
9#### `thread-starter.hoon`
13=* card card:agent:gall
18 def ~(. (default-agent this %|) bowl)
26 ?+ mark (on-poke:def mark vase)
28 ?+ q.vase (on-poke:def mark vase)
30 =/ tid `@ta`(cat 3 'thread_' (scot %uv (sham eny.bowl)))
31 =/ ta-now `@ta`(scot %da now.bowl)
32 =/ start-args [~ `tid byk.bowl p.q.vase !>(q.q.vase)]
35 [%pass /thread/[ta-now] %agent [our.bowl %spider] %poke %spider-start !>(start-args)]
39++ on-watch on-watch:def
40++ on-leave on-leave:def
43 |= [=wire =sign:agent:gall]
45 ?+ -.wire (on-agent:def wire sign)
47 ?+ -.sign (on-agent:def wire sign)
50 %- (slog leaf+"Thread started successfully" ~)
52 %- (slog leaf+"Thread failed to start" u.p.sign)
61And here's a minimal thread to test it with:
63#### `test-thread.hoon`
67=, strand=strand:spider
73?+ q.arg [~ %fail %not-foo ~]
79Save them as `/app/thread-starter.hoon` and `/ted/test-thread.hoon` respectively in the `%base` desk, `|commit %base`, and start the app with `|rein %base [& %thread-starter]`.
81Now you can poke it with a pair of thread name and argument like:
84:thread-starter [%test-thread %foo]
87You should see `Thread started successfully`.
89Now try poking it with `[%fake-thread %foo]`, you should see something like:
93/app/spider/hoon:<[355 5].[355 60]>
94[%no-file-for-thread %fake-thread]
95/app/spider/hoon:<[354 5].[355 60]>
96/app/spider/hoon:<[353 3].[359 19]>
97/app/spider/hoon:<[350 3].[359 19]>
98/app/spider/hoon:<[346 3].[359 19]>
99/app/spider/hoon:<[343 3].[359 19]>
100/app/spider/hoon:<[341 3].[359 19]>
101/app/spider/hoon:<[340 3].[359 19]>
102/app/spider/hoon:<[336 3].[359 19]>
103/app/spider/hoon:<[335 3].[359 19]>
104/app/spider/hoon:<[202 24].[202 68]>
105/app/spider/hoon:<[200 7].[207 9]>
106/app/spider/hoon:<[199 5].[208 17]>
107/app/spider/hoon:<[197 5].[208 17]>
108/app/spider/hoon:<[196 5].[208 17]>
109/sys/vane/gall/hoon:<[1.370 9].[1.370 37]>
114We can ignore the input logic, here's the important part:
117=/ tid `@ta`(cat 3 'thread_' (scot %uv (sham eny.bowl)))
118=/ ta-now `@ta`(scot %da now.bowl)
119=/ start-args [~ `tid byk.bowl p.q.vase !>(q.q.vase)]
122 [%pass /thread/[ta-now] %agent [our.bowl %spider] %poke %spider-start !>(start-args)]
126You can generate a tid any way you like, just make sure it's unique. Here we just use the hash of some entropy prefixed with `thread_`.
128Then it's just a poke to `%spider` with the mark `%spider-start` and a vase containing [start-args](/docs/userspace/threads/reference#start-thread). Spider will then respond with a `%poke-ack` with a `(unit tang)` which will be `~` if it started successfully or else contain an error and a traceback if it failed. Here we test for this and print the result:
132 |= [=wire =sign:agent:gall]
134 ?+ -.wire (on-agent:def wire sign)
136 ?+ -.sign (on-agent:def wire sign)
139 %- (slog leaf+"Thread started successfully" ~)
141 %- (slog leaf+"Thread failed to start" u.p.sign)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list