2020-11-06 23:55:32 +03:00
|
|
|
:: observe-hook:
|
2020-10-28 03:16:00 +03:00
|
|
|
::
|
2020-11-03 00:22:08 +03:00
|
|
|
:: helper that observes an app at a particular path and forwards all facts
|
|
|
|
:: to a particular thread. kills the subscription if the thread crashes
|
2020-10-28 03:16:00 +03:00
|
|
|
::
|
2020-11-06 23:55:32 +03:00
|
|
|
/- sur=observe-hook
|
2020-10-28 03:16:00 +03:00
|
|
|
/+ default-agent, dbug
|
|
|
|
::
|
|
|
|
|%
|
|
|
|
+$ card card:agent:gall
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-0
|
2020-11-30 22:20:27 +03:00
|
|
|
state-1
|
2020-10-28 03:16:00 +03:00
|
|
|
==
|
|
|
|
::
|
2020-11-07 00:29:15 +03:00
|
|
|
+$ serial @uv
|
|
|
|
+$ state-0 [%0 observers=(map serial observer:sur)]
|
2020-11-20 20:01:24 +03:00
|
|
|
+$ state-1 [%1 observers=(map serial observer:sur)]
|
|
|
|
::
|
2020-10-28 03:16:00 +03:00
|
|
|
++ got-by-val
|
2020-11-07 00:29:15 +03:00
|
|
|
|= [a=(map serial observer:sur) b=observer:sur]
|
|
|
|
^- serial
|
2020-10-28 03:16:00 +03:00
|
|
|
%- need
|
|
|
|
%+ roll ~(tap by a)
|
2020-11-07 00:29:15 +03:00
|
|
|
|= [[key=serial val=observer:sur] output=(unit serial)]
|
2020-10-28 03:16:00 +03:00
|
|
|
?:(=(val b) `key output)
|
|
|
|
--
|
|
|
|
::
|
|
|
|
%- agent:dbug
|
2020-12-01 01:32:53 +03:00
|
|
|
=| state-1
|
2020-10-28 03:16:00 +03:00
|
|
|
=* state -
|
|
|
|
::
|
|
|
|
^- agent:gall
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
::
|
2020-11-04 23:55:46 +03:00
|
|
|
++ on-init
|
|
|
|
|^ ^- (quip card _this)
|
|
|
|
:_ this
|
2020-11-20 20:01:24 +03:00
|
|
|
:~ %+ act
|
|
|
|
/inv-gra
|
|
|
|
[%watch %invite-store /invitatory/graph %invite-accepted-graph]
|
|
|
|
::
|
|
|
|
%+ act
|
|
|
|
/grp-gra
|
2020-12-01 01:30:20 +03:00
|
|
|
[%watch %group-store /groups %group-on-leave]
|
2020-11-20 20:01:24 +03:00
|
|
|
==
|
2020-11-04 23:55:46 +03:00
|
|
|
::
|
|
|
|
++ act
|
|
|
|
|= [=wire =action:sur]
|
|
|
|
^- card
|
|
|
|
:* %pass
|
|
|
|
wire
|
|
|
|
%agent
|
2020-11-06 23:55:32 +03:00
|
|
|
[our.bowl %observe-hook]
|
2020-11-04 23:55:46 +03:00
|
|
|
%poke
|
2020-11-06 23:55:32 +03:00
|
|
|
%observe-action
|
2020-11-04 23:55:46 +03:00
|
|
|
!> ^- action:sur
|
|
|
|
action
|
|
|
|
==
|
|
|
|
--
|
|
|
|
::
|
2020-11-03 00:22:08 +03:00
|
|
|
++ on-save !>(state)
|
2020-10-28 03:16:00 +03:00
|
|
|
++ on-load
|
|
|
|
|= old-vase=vase
|
|
|
|
^- (quip card _this)
|
2020-11-20 20:01:24 +03:00
|
|
|
=/ old-state !<(versioned-state old-vase)
|
|
|
|
?- -.old-state
|
2020-12-01 01:30:20 +03:00
|
|
|
%1 `this(state old-state)
|
2020-11-20 20:01:24 +03:00
|
|
|
::
|
|
|
|
%0
|
2020-11-30 22:20:27 +03:00
|
|
|
=. state [%1 observers.old-state]
|
2020-11-20 20:01:24 +03:00
|
|
|
%+ on-poke
|
|
|
|
%observe-action
|
|
|
|
!> ^- action:sur
|
2020-12-01 01:30:20 +03:00
|
|
|
[%watch %group-store /groups %group-on-leave]
|
2020-11-20 20:01:24 +03:00
|
|
|
==
|
2020-10-28 03:16:00 +03:00
|
|
|
::
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
?> (team:title our.bowl src.bowl)
|
2020-11-06 23:55:32 +03:00
|
|
|
?. ?=(%observe-action mark)
|
2020-10-28 03:16:00 +03:00
|
|
|
(on-poke:def mark vase)
|
2020-11-02 21:25:32 +03:00
|
|
|
=/ =action:sur !<(action:sur vase)
|
2020-10-29 23:02:09 +03:00
|
|
|
=* observer observer.action
|
2020-10-28 03:16:00 +03:00
|
|
|
=/ vals (silt ~(val by observers))
|
|
|
|
?- -.action
|
|
|
|
%watch
|
2020-11-06 23:55:32 +03:00
|
|
|
?: ?|(=(app.observer %spider) =(app.observer %observe-hook))
|
2020-10-28 03:16:00 +03:00
|
|
|
~|('we avoid infinite loops' !!)
|
2020-10-29 23:02:09 +03:00
|
|
|
?: (~(has in vals) observer)
|
2020-10-28 03:16:00 +03:00
|
|
|
~|('duplicate observer' !!)
|
2020-11-07 00:29:15 +03:00
|
|
|
:_ this(observers (~(put by observers) (sham eny.bowl) observer))
|
2020-10-28 03:16:00 +03:00
|
|
|
:_ ~
|
|
|
|
:* %pass
|
2020-11-07 00:29:15 +03:00
|
|
|
/observer/(scot %uv (sham eny.bowl))
|
2020-10-28 03:16:00 +03:00
|
|
|
%agent
|
2020-10-29 23:02:09 +03:00
|
|
|
[our.bowl app.observer]
|
2020-10-28 03:16:00 +03:00
|
|
|
%watch
|
2020-10-29 23:02:09 +03:00
|
|
|
path.observer
|
2020-10-28 03:16:00 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
%ignore
|
2020-10-29 23:02:09 +03:00
|
|
|
?. (~(has in vals) observer)
|
2020-10-28 03:16:00 +03:00
|
|
|
~|('cannot remove nonexistent observer' !!)
|
2020-10-29 23:02:09 +03:00
|
|
|
=/ key (got-by-val observers observer)
|
|
|
|
:_ this(observers (~(del by observers) key))
|
2020-10-28 03:16:00 +03:00
|
|
|
:_ ~
|
|
|
|
:* %pass
|
2020-11-07 00:29:15 +03:00
|
|
|
/observer/(scot %uv key)
|
2020-10-28 03:16:00 +03:00
|
|
|
%agent
|
2020-10-29 23:02:09 +03:00
|
|
|
[our.bowl app.observer]
|
2020-10-28 03:16:00 +03:00
|
|
|
%leave
|
|
|
|
~
|
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-agent
|
|
|
|
|= [=wire =sign:agent:gall]
|
|
|
|
^- (quip card _this)
|
2020-11-07 00:29:15 +03:00
|
|
|
|^
|
|
|
|
?+ wire (on-agent:def wire sign)
|
|
|
|
[%observer @ ~] on-observer
|
|
|
|
[%thread-result @ ~] on-thread-result
|
|
|
|
[%thread-start @ @ ~] on-thread-start
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-observer
|
|
|
|
?> ?=([%observer @ ~] wire)
|
|
|
|
?+ -.sign (on-agent:def wire sign)
|
|
|
|
%watch-ack
|
|
|
|
?~ p.sign [~ this]
|
|
|
|
=/ =serial (slav %uv i.t.wire)
|
|
|
|
~& watch-ack-deleting-observer+(~(got by observers) serial)
|
|
|
|
[~ this(observers (~(del by observers) serial))]
|
|
|
|
::
|
|
|
|
%kick
|
|
|
|
=/ =serial (slav %uv i.t.wire)
|
|
|
|
=/ =observer:sur (~(got by observers) serial)
|
2020-10-29 23:02:09 +03:00
|
|
|
:_ this
|
|
|
|
:_ ~
|
|
|
|
:* %pass
|
|
|
|
wire
|
|
|
|
%agent
|
|
|
|
[our.bowl app.observer]
|
|
|
|
%watch
|
|
|
|
path.observer
|
|
|
|
==
|
2020-11-07 00:29:15 +03:00
|
|
|
::
|
|
|
|
%fact
|
|
|
|
=/ =serial (slav %uv i.t.wire)
|
|
|
|
=/ =observer:sur (~(got by observers) serial)
|
|
|
|
=/ tid (scot %uv (sham eny.bowl))
|
|
|
|
:_ this
|
|
|
|
:~ :* %pass
|
|
|
|
[%thread-result i.t.wire ~]
|
|
|
|
%agent
|
|
|
|
[our.bowl %spider]
|
|
|
|
%watch
|
|
|
|
[%thread-result tid ~]
|
|
|
|
==
|
|
|
|
:* %pass
|
|
|
|
[%thread-start i.t.wire tid ~]
|
|
|
|
%agent
|
|
|
|
[our.bowl %spider]
|
|
|
|
%poke
|
|
|
|
%spider-start
|
|
|
|
!>([~ `tid thread.observer (slop q.cage.sign !>(~))])
|
|
|
|
== ==
|
2020-10-29 23:02:09 +03:00
|
|
|
==
|
2020-10-28 03:16:00 +03:00
|
|
|
::
|
2020-11-07 00:29:15 +03:00
|
|
|
++ on-thread-result
|
|
|
|
?> ?=([%thread-result @ ~] wire)
|
|
|
|
?+ -.sign (on-agent:def wire sign)
|
|
|
|
%kick [~ this]
|
|
|
|
%watch-ack [~ this]
|
|
|
|
::
|
|
|
|
%fact
|
2020-10-29 23:02:09 +03:00
|
|
|
?. =(p.cage.sign %thread-fail)
|
2020-11-05 03:42:52 +03:00
|
|
|
:_ this
|
|
|
|
:_ ~
|
|
|
|
:* %pass
|
|
|
|
wire
|
|
|
|
%agent
|
|
|
|
[our.bowl %spider]
|
|
|
|
%leave
|
|
|
|
~
|
|
|
|
==
|
2020-11-07 00:29:15 +03:00
|
|
|
=/ =serial (slav %uv i.t.wire)
|
|
|
|
=/ =observer:sur (~(got by observers) serial)
|
2020-11-05 03:42:52 +03:00
|
|
|
~& observer-failed+observer
|
2020-11-07 00:29:15 +03:00
|
|
|
:_ this(observers (~(del by observers) serial))
|
2020-11-05 03:42:52 +03:00
|
|
|
:~ :* %pass
|
|
|
|
[%observer i.t.wire ~]
|
|
|
|
%agent
|
|
|
|
[our.bowl app.observer]
|
|
|
|
%leave
|
|
|
|
~
|
|
|
|
==
|
|
|
|
:* %pass
|
|
|
|
wire
|
|
|
|
%agent
|
|
|
|
[our.bowl %spider]
|
|
|
|
%leave
|
|
|
|
~
|
|
|
|
==
|
|
|
|
==
|
2020-10-28 03:16:00 +03:00
|
|
|
==
|
2020-11-07 00:29:15 +03:00
|
|
|
::
|
|
|
|
++ on-thread-start
|
|
|
|
?> ?=([%thread-start @ @ ~] wire)
|
|
|
|
?. ?=(%poke-ack -.sign) (on-agent:def wire sign)
|
|
|
|
?~ p.sign [~ this]
|
|
|
|
=/ =serial (slav %uv i.t.wire)
|
|
|
|
=/ =observer:sur (~(got by observers) serial)
|
|
|
|
~& added-invalid-observer+observer
|
|
|
|
:_ this(observers (~(del by observers) serial))
|
|
|
|
:~ :* %pass
|
|
|
|
[%observer i.t.wire ~]
|
|
|
|
%agent
|
|
|
|
[our.bowl app.observer]
|
|
|
|
%leave
|
|
|
|
~
|
|
|
|
==
|
|
|
|
:* %pass
|
|
|
|
wire
|
|
|
|
%agent
|
|
|
|
[our.bowl app.observer]
|
|
|
|
%leave
|
|
|
|
~
|
|
|
|
== ==
|
|
|
|
--
|
2020-10-28 03:16:00 +03:00
|
|
|
::
|
|
|
|
++ on-watch on-watch:def
|
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-peek on-peek:def
|
|
|
|
++ on-arvo on-arvo:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|