Take Result
Two examples are provided: taking the result for a thread started by poking Spider directly, and taking the result for a thread started via the Khan vane.
When poking Spider directly
Here we'll look at taking the result of a thread we started by poking Spider directly. We've added an extra card to subscribe for the result and a couple of lines in +on-agent to test if it succeeded:
/- spider
=, strand=strand:spider
^- thread:spider
|= arg=vase
=/ m (strand ,vase)
^- form:m
|= strand-input:strand
?+ q.arg [~ %fail %not-foo ~]
%foo
[~ %done arg]
==Save these, |commit and then poke the app with :thread-starter [%test-thread %foo]. You should see:
Now try :thread-starter [%test-thread %bar]. You should see:
Analysis
In +on-poke we've added an extra card before the %spider-start poke to subscribe for the result:
If successful the thread will return a cage with a mark of %thread-done and a vase containing the result.
If the thread failed it will return a cage with a mark of %thread-fail and a vase containing [term tang] where $term is an error message and $tang is a traceback. In our case our thread fails with error %not-foo when its argument is not %foo.
Note that spider will automatically %kick us from the subscription after ending the thread and returning the result.
Here in on-agent we've added a test for %thread-fail or %thread-done and print the appropriate result.
When running a thread via Khan
Here's an example of a barebones Gall agent that runs a thread file via Khan and prints whether it succeeded.
And here's a minimal thread to test it with:
Save them as /app/thread-starter.hoon and /ted/test-thread.hoon respectively in the %base desk, |commit %base, and start the app with |start %thread-starter.
Now you can poke it with a pair of thread name and argument like:
You should see Thread success!.
Now try it with %bar instead:
You should see:
Analysis
In +on-arvo we expect a Khan %arow gift, which contains an (each cage goof). If the head of the $each is false, the thread failed, and the $goof contains the error. If the $each head is true, then the thread succeeded and it contains a $cage with the result. We handle both these cases and either print the error message or print success:
Last updated