urbit/pkg/arvo/app/example-tapp-subscribe.hoon

51 lines
1.3 KiB
Plaintext
Raw Normal View History

2019-05-28 23:23:06 +03:00
/+ tapp, stdio
=>
|%
+$ subscription-state
2019-05-29 01:38:14 +03:00
$: target=[her=ship app=term]
=path
2019-05-28 23:23:06 +03:00
==
+$ state
$: subscription=(unit subscription-state)
==
+$ peek-data _!!
2019-05-29 03:11:21 +03:00
+$ in-poke-data [%noun =cord]
+$ out-poke-data [%noun =cord]
2019-05-29 01:38:14 +03:00
+$ out-peer-data ~
+$ in-peer-data
$% [%comments comments=(list tape)]
==
++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data)
2019-05-29 03:11:21 +03:00
++ stdio (^stdio out-poke-data out-peer-data)
2019-05-28 23:23:06 +03:00
--
2019-06-01 00:44:47 +03:00
=, async=async:tapp
=, tapp-async=tapp-async:tapp
2019-05-28 23:23:06 +03:00
=, stdio
2019-05-29 01:38:14 +03:00
%- create-tapp-poke-diff:tapp
^- tapp-core-poke-diff:tapp
2019-05-28 23:23:06 +03:00
|_ [=bowl:gall state]
2019-05-29 03:11:21 +03:00
++ handle-poke
|= =in-poke-data
2019-06-01 00:44:47 +03:00
=/ m tapp-async
2019-05-28 23:23:06 +03:00
^- form:m
2019-05-29 03:11:21 +03:00
?: =(cord.in-poke-data 'pull')
2019-05-29 01:38:14 +03:00
?~ subscription
2019-06-01 00:44:47 +03:00
(async-fail %no-subscription ~)
2019-05-29 01:38:14 +03:00
;< ~ bind:m (pull-app [target path]:u.subscription)
(pure:m ~)
2019-05-31 00:43:27 +03:00
=/ target [our.bowl %example-tapp-fetch]
;< ~ bind:m (poke-app target %noun 'print')
;< ~ bind:m (peer-app target /comments)
=. subscription `[target /comments]
2019-05-29 01:38:14 +03:00
;< ~ bind:m (wait (add now.bowl ~s3))
(pure:m subscription)
::
++ handle-diff
|= [[her=ship app=term] =path data=in-peer-data]
2019-06-01 00:44:47 +03:00
=/ m tapp-async
2019-05-29 01:38:14 +03:00
^- form:m
?> ?=(%comments -.data)
2019-05-30 20:24:52 +03:00
~& subscriber-got-data=(lent comments.data)
2019-05-28 23:23:06 +03:00
(pure:m subscription)
--