@@ -18,124 +18,124 @@ Let's take a look at two apps, `:source` and `:sink`. First,
21− :: Sends subscription updates to sink.hoon
21+:: Sends subscription updates to sink.hoon
23− :::: /===/app/source/hoon
23+:::: /===/app/source/hoon
28− +$ move [bone card]
28+ +$ move [bone card]
29− +$ card $% [%diff diff-contents]
29+ +$ card $% [%diff diff-contents]
31− +$ diff-contents $% [%noun *]
31++$ diff-contents $% [%noun *]
35− |_ [bow=bowl:gall $~]
35+|_ [bow=bowl:gall $~]
37− ++ poke-noun
37+++ poke-noun
39− ^- [(list move) _+>.$]
39+ ^- [(list move) _+>.$]
41− %+ turn (prey /example-path bow)
41+ %+ turn (prey /example-path bow)
42− |=({o=bone *} [o %diff %noun non])
42+ |=({o=bone *} [o %diff %noun non])
44− ++ peer-example-path
44+++ peer-example-path
45− |= pax/path
45+ |= pax/path
46− ^- [(list move) _+>.$]
46+ ^- [(list move) _+>.$]
47− ~& source+peer-notify+'Someone subscribed to you!'
47+ ~& source+peer-notify+'Someone subscribed to you!'
48− ~& source+[ship+src.bow path+pax]
48+ ~& source+[ship+src.bow path+pax]
52− |= {wir=wire err=(unit tang)}
53− ^- [(list move) _+>.$]
55− ~& source+success+'Poke succeeded!'
52+ |= {wir=wire err=(unit tang)}
53+ ^- [(list move) _+>.$]
55+ ~& source+success+'Poke succeeded!'
57− ~& source+error+'Poke failed. Error:'
57+ ~& source+error+'Poke failed. Error:'
58− ~& source+error+err
58+ ~& source+error+err
62− |= [wir=wire err=(unit tang)]
62+ |= [wir=wire err=(unit tang)]
63− ^- [(list move) _+>.$]
63+ ^- [(list move) _+>.$]
65− ~& source+success+'Peer succeeded!'
65+ ~& source+success+'Peer succeeded!'
67+ ~& source+error+'Peer failed. Error:'
67− ~& source+error+'Peer failed. Error:'
74And secondly, `:sink`:
74And secondly, `:sink`:
77− :: Sets up a simple subscription to source.hoon
77+:: Sets up a simple subscription to source.hoon
79− :::: /===/app/sink/hoon
79+:::: /===/app/sink/hoon
83− +$ move [bone card]
83++$ move [bone card]
84− +$ card $% [%peer wire dock path]
84++$ card $% [%peer wire dock path]
85− [%pull wire dock $~]
85+ [%pull wire dock $~]
89− |_ [bow=bowl:gall val=?]
89+|_ [bow=bowl:gall val=?]
91− ++ poke-noun
91+++ poke-noun
93− ^- [(list move) _+>.$]
93+ ^- [(list move) _+>.$]
94− ?: &(=(%on non) val)
94+ ?: &(=(%on non) val)
95− :_ +>.$(val |)
95+ :_ +>.$(val |)
96− :~ :* ost.bow
96+ :~ :* ost.bow
98 /subscribe
98 /subscribe
99 [our.bow %source]
99 [our.bow %source]
100 /example-path
100 /example-path
103− ?: &(=(%off non) !val)
103+ ?: &(=(%off non) !val)
104− :_ +>.$(val &)
104+ :_ +>.$(val &)
105− ~[[ost.bow %pull /subscribe [our.bow %source] ~]]
105+ ~[[ost.bow %pull /subscribe [our.bow %source] ~]]
106− ~& ?: val
106+ ~& ?: val
107− sink+unsubscribed+'You are now unsubscribed!'
107+ sink+unsubscribed+'You are now unsubscribed!'
108− sink+subscribed+'You are now subscribed!'
108+ sink+subscribed+'You are now subscribed!'
113− ^- [(list move) _+>.$]
114− ~& sink+received-data+'You got something!'
119− |= [wir=wire err=(unit tang)]
120− ^- [(list move) _+>.$]
122− ~& sink+success+'Poke succeeded!'
124− ~& sink+error+'Poke failed. Error:'
128− ++ reap
111+++ diff-noun
129− |= [wir=wire err=(unit tang)]
112+ |= [wir=wire non=*]
130− ^- [(list move) _+>.$]
113+ ^- [(list move) _+>.$]
131− ?~ err
114+ ~& sink+received-data+'You got something!'
132− ~& sink+success+'Peer succeeded!'
115+ ~& sink+data+non
119+ |= [wir=wire err=(unit tang)]
120+ ^- [(list move) _+>.$]
122+ ~& sink+success+'Poke succeeded!'
134− ~& sink+error+'Peer failed. Error:'
124+ ~& sink+error+'Poke failed. Error:'
135− ~& sink+error+err
125+ ~& sink+error+err
136− [~ +>.$]
126+ [~ +>.$]
129+ |= [wir=wire err=(unit tang)]
130+ ^- [(list move) _+>.$]
132+ ~& sink+success+'Peer succeeded!'
134+ ~& sink+error+'Peer failed. Error:'
141Two notes:
141Two notes:
@@ -147,32 +147,39 @@ Two notes:
147Here's some sample output of the two working together:
147Here's some sample output of the two working together:
150− ~fintud-macrep:dojo> |start %source
150+~fintud-macrep:dojo> |start %source
152− ~fintud-macrep:dojo> |start %sink
153+~fintud-macrep:dojo> |start %sink
154− ~fintud-macrep:dojo> :sink %on
156+~fintud-macrep:dojo> :sink %on
155− [%source %peer-notify 'Someone subscribed to you!']
157+[%source %peer-notify 'Someone subscribed to you!']
156− [%source [%ship ~fintud-macrep] %path /]
158+[%source [%ship ~fintud-macrep] %path /]
157− [%sink %success 'Peer succeeded!']
159+[%sink %success 'Peer succeeded!']
159− ~fintud-macrep:dojo> :source 5
162+~fintud-macrep:dojo> :source 5
160− [%sink %received-data 'You got something!']
163+[%sink %received-data 'You got something!']
161− [%sink %data 5]
164+[%sink %data 5]
163− ~fintud-macrep:dojo> :sink %off
167+~fintud-macrep:dojo> :sink %off
165− ~fintud-macrep:dojo> :source 6
170+~fintud-macrep:dojo> :source 6
167− ~fintud-macrep:dojo> :sink %on
173+~fintud-macrep:dojo> :sink %on
168− [%source %peer-notify 'Someone subscribed to you!']
174+[%source %peer-notify 'Someone subscribed to you!']
169− [%source [%ship ~fintud-macrep] %path /]
175+[%source [%ship ~fintud-macrep] %path /]
170− [%sink %success 'Peer succeeded!']
176+[%sink %success 'Peer succeeded!']
172− ~fintud-macrep:dojo> :source 7
179+~fintud-macrep:dojo> :source 7
173− [%sink %received-data 'You got something!']
180+[%sink %received-data 'You got something!']
174− [%sink %data 7]
181+[%sink %data 7]
178### :source
185### :source
@@ -190,8 +197,8 @@ Our definition of `move` is fairly specific, since we're only going to
190sending one kind of move. The `%diff` move is a subscription update, and
197sending one kind of move. The `%diff` move is a subscription update, and
191its content is marked data which gall routes to our subscribers.
198its content is marked data which gall routes to our subscribers.
193−This is a slightly different kind of move than [we've dealt with so
200+This is a slightly different kind of move than we've dealt with so
194−far](/arvo/network). It's producing a result rather than calling other
201+far. It's producing a result rather than calling other
195code (i.e. it's a return rather than a function call), so if you recall
202code (i.e. it's a return rather than a function call), so if you recall
196the discussion of ducts, a layer gets popped off the duct rather than
203the discussion of ducts, a layer gets popped off the duct rather than
197added to it. This is why no wire is needed for the move -- we won't
204added to it. This is why no wire is needed for the move -- we won't
@@ -227,7 +234,7 @@ that begins with the given path. "Prey" is short for "prefix".
227Now we have the list of relevant subscribers. This a list of triples,
234Now we have the list of relevant subscribers. This a list of triples,
228`{bone @p path}`, where the only thing we really need is the bone, because we
235`{bone @p path}`, where the only thing we really need is the bone, because we
229don't need to know their urbit or what exact path they subscribed on. Thus, our
236don't need to know their urbit or what exact path they subscribed on. Thus, our
230−transformer function takes `{o/bone *}` and produces `[o %diff %noun non]`,
237+transformer function takes `[o=bone *]` and produces `[o %diff %noun non]`,
231which is a move that provides bone `o` with this subscription update:
238which is a move that provides bone `o` with this subscription update:
232`[%noun non]`". This is fairly dense code, but what it's doing is
239`[%noun non]`". This is fairly dense code, but what it's doing is
233straightforward!
240straightforward!
@@ -251,7 +258,7 @@ your bone and wire are the same as when you subscribed, then the cancellation
251will happen correctly.
258will happen correctly.
253The only state we need for `:sink` is a boolean to indicate whether
260The only state we need for `:sink` is a boolean to indicate whether
254−we're already subscribed to `:source`. We use `val/?`, where `?`
261+we're already subscribed to `:source`. We use `val=?`, where `?`
255is the sign of type boolean (similar to `*`, `@`), which defaults to true (that
262is the sign of type boolean (similar to `*`, `@`), which defaults to true (that
@@ -260,13 +267,13 @@ available (`val` is true). If so, we produce the move to subscribe to
260`:source`:
267`:source`:
263− :~ :* ost.bow
270+:~ :* ost.bow
265− /subscribe
272+ /subscribe
266− [our.bow %source]
273+ [our.bow %source]
267− /example-path
274+ /example-path
272Also, in the preceding lines, we set `val` to false (`|`) with `+>.$(val |)`.
279Also, in the preceding lines, we set `val` to false (`|`) with `+>.$(val |)`.
@@ -281,8 +288,8 @@ is false), then we unsubscribe from `:source` and set `val` back to true (`&`),
281again using our handy inverted cell constructor mold `:_`:
288again using our handy inverted cell constructor mold `:_`:
284− :_ +>.$(val &)
291+:_ +>.$(val &)
285− ~[[ost.bow %pull /subscribe [our.bow %source] ~]]
292+~[[ost.bow %pull /subscribe [our.bow %source] ~]]
288It's important to send over the same bone and wire (`/subscribe`) as the
295It's important to send over the same bone and wire (`/subscribe`) as the
@@ -293,10 +300,10 @@ state, based on whether `val` is true or false, and return a cell containing
293a null list of moves and our unchanged app state:
300a null list of moves and our unchanged app state:
296− ~& ?: val
303+~& ?: val
297− sink+unsubscribed+'You are now unsubscribed!'
304+ sink+unsubscribed+'You are now unsubscribed!'
298− sink+subscribed+'You are now subscribed!'
305+ sink+subscribed+'You are now subscribed!'
299− [~ +>.$]
306+[~ +>.$]
302`++diff-noun` is called when we get a `%diff` update along a subscription with a
309`++diff-noun` is called when we get a `%diff` update along a subscription with a
@@ -305,8 +312,8 @@ the `%peer` subscription request along and the data we got back. In our case we
305just print out the data:
312just print out the data:
308− ~& sink+received-data+'You got something!'
315+~& sink+received-data+'You got something!'
309− ~& sink+data+non
316+~& sink+data+non
312`++reap` is called when we receive an acknowledgment as to whether the
319`++reap` is called when we receive an acknowledgment as to whether the