on cd23ade help sign in
75 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](../index.md#gall) and for some examples see [here](../index.md#how-tos--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](../reference.md).
16## Threads
17- are like transient gall agents
18- are used mostly to chain a series of IO operations
19- can be used by gall agents to spin out IO operations
20- live in the `ted` directory
21- are managed by the gall agent `spider`
22- take a `vase` and produce a `strand` which produces a `vase`
24#### Example
26```hoon
27/- spider
28=, strand=strand:spider
29^- thread:spider
30|= arg=vase
31=/ m (strand ,vase)
32^- form:m
33(pure:m arg)
34```
36## Strands
38- are the building blocks of threads
39- 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.
40- must be specialised to produce a particular type like `(strand ,@ud)`.
41- are conventionally given the face `m`.
42- are a core that has three main arms - `form`, `pure` and `bind`:
44#### form
45- is the mold of the strand suitable for casting
46- is the type returned by the other arms
47#### pure
48- simply returns the `form` of a `strand` that produces pure's argument without doing any IO
49#### bind
50- is used to chain strands together like javascript promises
51- is used in conjunction with micgal (`;<`)
52- must be specialised to a type like `;< <type> bind:m ...`
53- takes two arguments. The first is a function that returns the `form` of a `strand` that produces `<type>`. The second is a gate whose sample is `<type>` and which returns a `form`.
54- calls the first and then, if it succeeded, calls the second with the result of the first as its sample.
56## Strand input
58- looks like `[=bowl in=(unit input)]`
59- `bowl` has things like `our`, `now`, `eny` and so forth
60- `bowl` is populated once when the thread is first called and then every time it receives new input
61- `input` contains any incoming pokes, signs and watches.
63## Strand output
65- contains `[cards=(list card:agent:gall) <response>]`
66- `cards` are any cards to be sent immediately
67- `<response>` is something like `[%done value]`, `[%fail err]`, etc.
68- `%done` will contain the result
69- responses are only used internally to manage the flow of the thread and are not returned to subscribers.
71## Strandio
73- is located in `/lib/strandio/hoon`
74- contains a collection of ready-made functions for use in threads
75- eg. `sleep`, `get-bowl`, `take-watch`, `poke`, `fetch-json`, etc.