diff --git a/app/example-tapp-fetch.hoon b/app/example-tapp-fetch.hoon index f6294672d7..fcecce41e4 100644 --- a/app/example-tapp-fetch.hoon +++ b/app/example-tapp-fetch.hoon @@ -12,13 +12,14 @@ +$ state $: top-comments=(list tape) == + +$ peek-data _!! +$ in-poke-data [%noun =cord] +$ out-poke-data ~ +$ in-peer-data ~ +$ out-peer-data $% [%comments (list tape)] == - ++ tapp (^tapp state in-poke-data out-poke-data in-peer-data out-peer-data) + ++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data) ++ stdio (^stdio out-poke-data out-peer-data) -- => diff --git a/app/example-tapp-subscribe.hoon b/app/example-tapp-subscribe.hoon index 78927d7087..42b10f86f5 100644 --- a/app/example-tapp-subscribe.hoon +++ b/app/example-tapp-subscribe.hoon @@ -8,13 +8,14 @@ +$ state $: subscription=(unit subscription-state) == + +$ peek-data _!! +$ in-poke-data [%noun =cord] +$ out-poke-data [%noun =cord] +$ out-peer-data ~ +$ in-peer-data $% [%comments comments=(list tape)] == - ++ tapp (^tapp state in-poke-data out-poke-data in-peer-data out-peer-data) + ++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data) ++ stdio (^stdio out-poke-data out-peer-data) -- =, async=async:tapp diff --git a/lib/tapp.hoon b/lib/tapp.hoon index 7176d6f756..4a1b607b5d 100644 --- a/lib/tapp.hoon +++ b/lib/tapp.hoon @@ -1,6 +1,7 @@ /- tapp-sur=tapp /+ async |* $: state-type=mold + peek-data=mold in-poke-data=mold out-poke-data=mold in-peer-data=mold @@ -12,7 +13,8 @@ ++ sign sign:tapp-sur ++ contract contract:tapp-sur ++ command - $% [%poke =in-poke-data] + $% [%init ~] + [%poke =in-poke-data] [%peer =path] [%diff =dock =path =in-peer-data] [%take =sign] @@ -28,6 +30,8 @@ active=(unit eval-form:eval:tapp-async) app-state=state-type == ++$ tapp-peek + [%noun ?(? (set contract))] :: :: The form of a tapp that only handles pokes :: @@ -44,7 +48,11 @@ %- create-tapp-poke-peer |_ [=bowl:gall state=state-type] ++ handle-poke ~(handle-poke handler bowl state) - ++ handle-peer |=(* (async-fail:async-lib %no-peer-handler >path< ~)) + ++ handle-peer + |= * + ~| %default-tapp-no-sole + ?< ?=([%sole *] +<) + (async-fail:async-lib %no-peer-handler >path< ~) -- :: :: The form of a tapp that only handles pokes and peers @@ -65,7 +73,9 @@ |= handler=tapp-core-poke-peer %- create-tapp-all |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ ++ handle-peer ~(handle-peer handler bowl state) ++ handle-diff |=(* (async-fail:async-lib %no-diff-handler >path< ~)) ++ handle-take |=(* (async-fail:async-lib %no-take-handler >path< ~)) @@ -89,7 +99,9 @@ |= handler=tapp-core-poke-diff %- create-tapp-all |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ ++ handle-peer |=(* (async-fail:async-lib %no-peer-handler >path< ~)) ++ handle-diff ~(handle-diff handler bowl state) ++ handle-take |=(* (async-fail:async-lib %no-take-handler >path< ~)) @@ -117,24 +129,71 @@ |= handler=tapp-core-poke-peer-take %- create-tapp-all |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ ++ handle-peer ~(handle-peer handler bowl state) ++ handle-diff |=(* (async-fail:async-lib %no-diff-handler >path< ~)) ++ handle-take ~(handle-take handler bowl state) -- :: +:: The form of a tapp that only handles pokes, peers, diffs, and takes +:: +++ tapp-core-poke-peer-diff-take + $_ ^| + |_ [bowl:gall state-type] + ++ handle-poke + |~ in-poke-data + *form:tapp-async + :: + ++ handle-peer + |~ path + *form:tapp-async + :: + ++ handle-diff + |~ [dock path in-peer-data] + *form:tapp-async + :: + ++ handle-take + |~ sign + *form:tapp-async + -- +:: +++ create-tapp-poke-peer-diff-take + |= handler=tapp-core-poke-peer-diff-take + %- create-tapp-all + |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async + ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ + ++ handle-peer ~(handle-peer handler bowl state) + ++ handle-diff ~(handle-diff handler bowl state) + ++ handle-take ~(handle-take handler bowl state) + -- +:: :: The form of a tapp :: ++ tapp-core-all $_ ^| |_ [bowl:gall state-type] :: + :: Initialization + :: + ++ handle-init + *form:tapp-async + :: :: Input :: ++ handle-poke |~ in-poke-data *form:tapp-async :: + :: Read + :: + ++ handle-peek + |~ path + *(unit (unit peek-data)) + :: :: Subscription request :: ++ handle-peer @@ -159,12 +218,18 @@ |_ [=bowl:gall tapp-state] ++ this-tapp . ++ prep - |= old-state=* + |= old-state=(unit) ^- (quip move _this-tapp) - ~& [%tapp-loaded dap.bowl] - =/ old ((soft tapp-state) old-state) + ?~ old-state + ~& [%tapp-init dap.bowl] + =. waiting (~(put to waiting) %init ~) + start-async + :: + =/ old ((soft tapp-state) u.old-state) ?~ old + ~& [%tapp-reset dap.bowl] `this-tapp + ~& [%tapp-loaded dap.bowl] `this-tapp(+<+ u.old) :: :: Start a command @@ -178,6 +243,22 @@ `this-tapp start-async :: + :: Read from tapp state + :: + ++ peek + |= =path + ^- (unit (unit ?(tapp-peek peek-data))) + ?- path + [%x %tapp %active ~] + [~ ~ %noun ?=(^ active)] + :: + [%x %tapp %contracts ~] + [~ ~ %noun ?~(active ~ contracts.u.active)] + :: + * + (~(handle-peek handler bowl app-state) path) + == + :: :: Receive subscription request :: ++ peer @@ -310,6 +391,7 @@ %- from-form:eval:tapp-async ^- form:tapp-async ?- -.u.next + %init ~(handle-init handler bowl app-state) %poke (~(handle-poke handler bowl app-state) +.u.next) %peer (~(handle-peer handler bowl app-state) +.u.next) %diff (~(handle-diff handler bowl app-state) +.u.next)