7The input to a `strand` is defined in `/lib/strand/hoon` as:
10+$ strand-input [=bowl in=(unit input)]
13When a thread is first started, spider will populate the `bowl` and provide it along with an `input` of `~`. If/when new input comes in (such as a poke, sign or watch) it will provide a new updated bowl along with the new input.
15For example, here's a thread that gets the time from the bowl, runs an IO-less function that takes one or two seconds to compute, and then gets the time again:
20=, strand=strand:spider
25 ?: =(n 0) $(m (dec m), n 1)
26 $(m (dec m), n $(n (dec n)))
32;< t1=@da bind:m get-time
34;< t2=@da bind:m get-time
38Since it never does any IO, `t1` and `t2` are the same: `[~2021.3.17..07.47.39..e186 ~2021.3.17..07.47.39..e186]`. However, if we replace the ackermann function with a 2 second `sleep` from strandio:
43=, strand=strand:spider
48;< t1=@da bind:m get-time
49;< ~ bind:m (sleep ~s2)
50;< t2=@da bind:m get-time
54...and run it again we get different values for `t1` and `t2`: `[~2021.3.17..07.50.28..8a5d ~2021.3.17..07.50.30..8a66]`. This is because `sleep` gets a `%wake` sign back from `behn`, so spider updates the time in the bowl along with it.
56Now let's look at the contents of `bowl` and `input` in detail:
60`bowl` is the following:
77- `src` - ship where input is coming from
78- `tid` - ID of this thread
79- `mom` - parent thread if this is a child thread
80- `wex` - outgoing subscriptions
81- `sup` - incoming subscriptions
83- `now` - current datetime
84- `byk` - `[p=ship q=desk r=case]` path prefix
86There are a number of functions in `strandio` to access the `bowl` contents like `get-bowl`, `get-beak`, `get-time`, `get-our` and `get-entropy`.
88You can also write a function with a gate whose sample is `strand-input:strand` and access the bowl that way like:
93=, strand=strand:spider
97 =/ m (strand ,[boat:gall bitt:gall])
99 |= tin=strand-input:strand
100 `[%done [wex.bowl.tin sup.bowl.tin]]
106;< res=[boat:gall bitt:gall] bind:m bowl-stuff
112`input` is defined in libstrand as:
117 [%sign =wire =sign-arvo]
118 [%agent =wire =sign:agent:gall]
123- `%poke` incoming poke
124- `%sign` incoming sign from arvo
125- `%agent` incoming sign from a gall agent
126- `%watch` incoming subscription
128Various functions in `strandio` will check `input` and conditionally do things based on its contents. For example, `sleep` sets a `behn` timer and then calls `take-wake` to wait for a `%wake` sign from behn:
135 |= tin=strand-input:strand
138 [~ %sign [%wait @ ~] %behn %wake *]
139 ?. |(?=(~ until) =(`u.until (slaw %da i.t.wire.u.in.tin)))
141 ?~ error.sign-arvo.u.in.tin
143 `[%fail %timer-error u.error.sign-arvo.u.in.tin]
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