on 514b5fc help sign in
81 lines 2.9 kB history raw
1+++
2title = "Summary"
3weight = 5
4template = "doc.html"
5+++
7That's basically all you need to know to write threads. The best way to get a good handle on them is just to experiment with some `strandio` functions. For information on running threads from gall agents, see [here](/docs/userspace/threads/gall) and for some examples see [here](/docs/userspace/threads/examples).
9Now here's a quick recap of the main points covered:
11## Spider
13- is the gall agent that manages threads.
14- Details of interacting with threads via spider can be seen [here](/docs/userspace/threads/reference).
16## Threads
18- are like transient gall agents
19- are used mostly to chain a series of IO operations
20- can be used by gall agents to spin out IO operations
21- live in the `ted` directory
22- are managed by the gall agent `spider`
23- take a `vase` and produce a `strand` which produces a `vase`
25#### Example
27```hoon
28/- spider
29=, strand=strand:spider
30^- thread:spider
31|= arg=vase
32=/ m (strand ,vase)
33^- form:m
34(pure:m arg)
35```
37## Strands
39- are the building blocks of threads
40- take [this](https://github.com/urbit/urbit/blob/master/pkg/arvo/lib/strand.hoon#L2-L21) input and produce [this](https://github.com/urbit/urbit/blob/master/pkg/arvo/lib/strand.hoon#L23-L48) output.
41- must be specialised to produce a particular type like `(strand ,@ud)`.
42- are conventionally given the face `m`.
43- are a core that has three main arms - `form`, `pure` and `bind`:
45### form
47- is the mold of the strand suitable for casting
48- is the type returned by the other arms
50### pure
52- simply returns the `form` of a `strand` that produces pure's argument without doing any IO
54### bind
56- is used to chain strands together like javascript promises
57- is used in conjunction with micgal (`;<`)
58- must be specialised to a type like `;< &lt;type> bind:m ...`
59- takes two arguments. The first is a function that returns the `form` of a `strand` that produces `&lt;type>`. The second is a gate whose sample is `&lt;type>` and which returns a `form`.
60- calls the first and then, if it succeeded, calls the second with the result of the first as its sample.
62## Strand input
64- looks like `[=bowl in=(unit input)]`
65- `bowl` has things like `our`, `now`, `eny` and so forth
66- `bowl` is populated once when the thread is first called and then every time it receives new input
67- `input` contains any incoming pokes, signs and watches.
69## Strand output
71- contains `[cards=(list card:agent:gall) &lt;response>]`
72- `cards` are any cards to be sent immediately
73- `&lt;response>` is something like `[%done value]`, `[%fail err]`, etc.
74- `%done` will contain the result
75- responses are only used internally to manage the flow of the thread and are not returned to subscribers.
77## Strandio
79- is located in `/lib/strandio/hoon`
80- contains a collection of ready-made functions for use in threads
81- eg. `sleep`, `get-bowl`, `take-watch`, `poke`, `fetch-json`, etc.