-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
=< subscriber | ||
|% | ||
+$ sub | ||
$: =dock | ||
=path | ||
fires-at=@da | ||
== | ||
:: | ||
+$ subs (map wire sub) | ||
:: | ||
++ verb | | ||
++ subscriber | ||
|_ [=subs bowl:gall] | ||
++ interval ~s30 | ||
++ handle-wakeup | ||
|= =wire | ||
^- [(list card:agent:gall) _subs] | ||
?> ?=([%~.~ %retry *] wire) | ||
~? verb ['waking up' wire] | ||
=/ sub (~(get by subs) t.t.wire) | ||
?~ sub [~ subs] | ||
:- ~[[%pass t.t.wire %agent dock.u.sub %watch path.u.sub]] | ||
(~(del by subs) t.t.wire) | ||
++ subscribe | ||
|= [=wire =dock =path delay=?] | ||
^- [(list card:agent:gall) _subs] | ||
?: (~(has by subs) wire) | ||
((slog 'Duplicate subscription' >[wire dock]< ~) [~ subs]) | ||
?. delay [~[[%pass wire %agent dock %watch path]] subs] | ||
~? verb ['subscribing with delay' wire] | ||
=/ fires-at (add now interval) | ||
:_ (~(put by subs) wire [dock path fires-at]) | ||
~[[%pass (weld /~/retry wire) %arvo %b %wait fires-at]] | ||
++ unsubscribe | ||
|= [=wire =dock] | ||
^- [(list card:agent:gall) _subs] | ||
=/ leave [%pass wire %agent dock %leave ~] | ||
=/ sub (~(get by subs) wire) | ||
?~ sub | ||
((slog 'No such subscription' >[wire]< ~) [~[leave] subs]) | ||
~? verb ['cancelling' wire] | ||
:_ (~(del by subs) wire) | ||
:~ [%pass (weld /~/retry wire) %arvo %b %rest fires-at.u.sub] | ||
leave | ||
== | ||
-- | ||
-- |