2019-05-29 01:38:14 +03:00
|
|
|
:: Standard input/output functions.
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
|
|
|
:: These are all asynchronous computations, which means they produce a
|
2019-06-01 00:44:47 +03:00
|
|
|
:: form:(async A) for some type A. You can always tell what they
|
2019-05-26 08:14:08 +03:00
|
|
|
:: produce by checking their first three lines.
|
|
|
|
::
|
|
|
|
:: Functions with the word "raw" in their name are for internal use
|
|
|
|
:: only because they carry a high salmonella risk. More specifcally,
|
|
|
|
:: improper use of them may result in side effects that the tapp
|
|
|
|
:: runtime doesn't know about and can't undo in case the transaction
|
|
|
|
:: fails.
|
|
|
|
::
|
|
|
|
/- tapp-sur=tapp
|
2019-06-01 00:44:47 +03:00
|
|
|
/+ async
|
2019-05-29 01:38:14 +03:00
|
|
|
|* [poke-data=mold out-peer-data=mold]
|
|
|
|
=/ tapp-sur (tapp-sur poke-data out-peer-data)
|
2019-05-26 08:14:08 +03:00
|
|
|
=, card=card:tapp-sur
|
|
|
|
=, sign=sign:tapp-sur
|
|
|
|
=, contract=contract:tapp-sur
|
2019-06-01 00:44:47 +03:00
|
|
|
=+ (async sign card contract)
|
2019-05-26 08:14:08 +03:00
|
|
|
|%
|
|
|
|
::
|
|
|
|
:: Raw power
|
|
|
|
::
|
|
|
|
++ send-raw-card
|
|
|
|
|= =card
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-06-01 00:44:47 +03:00
|
|
|
|= =async-input
|
2019-05-31 00:43:27 +03:00
|
|
|
[[card]~ ~ ~ %done ~]
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
|
|
|
:: Add or remove a contract
|
|
|
|
::
|
|
|
|
++ set-raw-contract
|
|
|
|
|= [add=? =contract]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-06-21 10:35:07 +03:00
|
|
|
|= =async-input
|
|
|
|
=/ delta=contract-delta:async
|
|
|
|
?.(add [%lose ~] [%gain ost.bowl.async-input])
|
|
|
|
[~ ~ (my [contract delta] ~) %done ~]
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
2019-05-29 01:38:14 +03:00
|
|
|
:: Send effect on current bone
|
2019-05-28 23:23:06 +03:00
|
|
|
::
|
|
|
|
++ send-effect
|
|
|
|
|= =card
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-28 23:23:06 +03:00
|
|
|
^- form:m
|
2019-05-29 01:38:14 +03:00
|
|
|
;< =bone bind:m
|
2019-06-01 00:44:47 +03:00
|
|
|
|= =async-input
|
|
|
|
[~ ~ ~ %done ost.bowl.async-input]
|
2019-05-29 01:38:14 +03:00
|
|
|
(send-effect-on-bone bone card)
|
|
|
|
::
|
|
|
|
:: Send effect on particular bone
|
|
|
|
::
|
|
|
|
++ send-effect-on-bone
|
|
|
|
|= [=bone =card]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-29 01:38:14 +03:00
|
|
|
^- form:m
|
2019-06-01 00:44:47 +03:00
|
|
|
|= async-input
|
2019-05-29 01:38:14 +03:00
|
|
|
[~ [bone card]~ ~ %done ~]
|
2019-05-28 23:23:06 +03:00
|
|
|
::
|
2019-05-26 08:14:08 +03:00
|
|
|
:: ----
|
|
|
|
::
|
2019-06-26 03:00:30 +03:00
|
|
|
:: Outgoing HTTP requests
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
2019-06-26 03:00:30 +03:00
|
|
|
++ send-request
|
|
|
|
|= =request:http
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-06-20 22:42:38 +03:00
|
|
|
=/ =card
|
2019-07-04 09:45:54 +03:00
|
|
|
[%request / request *outbound-config:iris]
|
2019-06-20 22:42:38 +03:00
|
|
|
;< ~ bind:m (send-raw-card card)
|
|
|
|
(set-raw-contract & %request ~)
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
2019-06-26 03:00:30 +03:00
|
|
|
++ send-hiss
|
|
|
|
|= =hiss:eyre
|
|
|
|
=/ m (async ,~)
|
|
|
|
^- form:m
|
|
|
|
(send-request (hiss-to-request:html hiss))
|
|
|
|
::
|
2019-06-20 22:42:38 +03:00
|
|
|
:: Wait until we get an HTTP response or cancelation
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
2019-06-26 03:00:30 +03:00
|
|
|
++ take-response-raw
|
2019-07-04 09:45:54 +03:00
|
|
|
=/ m (async (unit client-response:iris))
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-06-01 00:44:47 +03:00
|
|
|
|= =async-input
|
2019-05-26 08:14:08 +03:00
|
|
|
:^ ~ ~ ~
|
2019-06-01 00:44:47 +03:00
|
|
|
?~ in.async-input
|
2019-05-26 08:14:08 +03:00
|
|
|
[%wait ~]
|
2019-06-06 09:43:48 +03:00
|
|
|
=* sign sign.u.in.async-input
|
2019-06-20 22:42:38 +03:00
|
|
|
:: fail on anything other than an http-response
|
|
|
|
::
|
|
|
|
?. ?=(%http-response -.sign)
|
|
|
|
[%fail %expected-http-response >got=-.sign< ~]
|
|
|
|
?- -.response.sign
|
|
|
|
:: ignore progress notifications
|
|
|
|
::
|
|
|
|
%progress
|
|
|
|
[%wait ~]
|
|
|
|
::
|
|
|
|
%cancel
|
|
|
|
[%done ~]
|
|
|
|
::
|
|
|
|
%finished
|
2019-06-26 03:00:30 +03:00
|
|
|
[%done (some response.sign)]
|
2019-06-20 22:42:38 +03:00
|
|
|
==
|
2019-06-26 03:00:30 +03:00
|
|
|
:: Wait until we get an HTTP response or cancelation and unset contract
|
|
|
|
::
|
|
|
|
++ take-maybe-response
|
2019-07-04 09:45:54 +03:00
|
|
|
=/ m (async (unit client-response:iris))
|
2019-06-26 03:00:30 +03:00
|
|
|
^- form:m
|
2019-07-04 09:45:54 +03:00
|
|
|
;< rep=(unit client-response:iris) bind:m
|
2019-06-26 03:00:30 +03:00
|
|
|
take-response-raw
|
|
|
|
;< ~ bind:m (set-raw-contract | %request ~)
|
|
|
|
(pure:m rep)
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
|
|
|
:: Wait until we get an HTTP response and unset contract
|
|
|
|
::
|
2019-06-26 03:00:30 +03:00
|
|
|
++ take-response
|
2019-07-04 09:45:54 +03:00
|
|
|
=/ m (async (unit client-response:iris))
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-07-04 09:45:54 +03:00
|
|
|
;< rep=(unit client-response:iris) bind:m
|
2019-06-26 03:00:30 +03:00
|
|
|
take-maybe-response
|
2019-06-20 22:42:38 +03:00
|
|
|
?^ rep
|
2019-06-26 03:00:30 +03:00
|
|
|
(pure:m rep)
|
2019-06-20 22:42:38 +03:00
|
|
|
|= =async-input
|
|
|
|
[~ ~ ~ %fail %http-canceled ~]
|
2019-06-06 09:43:48 +03:00
|
|
|
::
|
2019-06-20 22:42:38 +03:00
|
|
|
:: Wait until we get an HTTP response or cancelation and unset contract
|
2019-06-06 09:43:48 +03:00
|
|
|
::
|
2019-06-20 22:42:38 +03:00
|
|
|
++ take-maybe-sigh
|
|
|
|
=/ m (async (unit httr:eyre))
|
2019-06-06 09:43:48 +03:00
|
|
|
^- form:m
|
2019-07-04 09:45:54 +03:00
|
|
|
;< rep=(unit client-response:iris) bind:m
|
2019-06-26 03:00:30 +03:00
|
|
|
take-maybe-response
|
|
|
|
?~ rep
|
|
|
|
(pure:m ~)
|
|
|
|
:: XX s/b impossible
|
|
|
|
::
|
|
|
|
?. ?=(%finished -.u.rep)
|
|
|
|
(pure:m ~)
|
2019-07-04 09:45:54 +03:00
|
|
|
(pure:m (some (to-httr:iris +.u.rep)))
|
2019-06-26 03:00:30 +03:00
|
|
|
::
|
|
|
|
:: Wait until we get an HTTP response and unset contract
|
|
|
|
::
|
|
|
|
++ take-sigh
|
|
|
|
=/ m (async ,httr:eyre)
|
|
|
|
^- form:m
|
|
|
|
;< rep=(unit httr:eyre) bind:m take-maybe-sigh
|
|
|
|
?^ rep
|
|
|
|
(pure:m u.rep)
|
|
|
|
|= =async-input
|
|
|
|
[~ ~ ~ %fail %http-canceled ~]
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
|
|
|
:: Extract body from raw httr
|
|
|
|
::
|
|
|
|
++ extract-httr-body
|
|
|
|
|= =httr:eyre
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,cord)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
|
|
|
?. =(2 (div p.httr 100))
|
2019-06-01 00:44:47 +03:00
|
|
|
(async-fail %httr-error >p.httr< >+.httr< ~)
|
2019-05-26 08:14:08 +03:00
|
|
|
?~ r.httr
|
2019-06-01 00:44:47 +03:00
|
|
|
(async-fail %expected-httr-body >httr< ~)
|
2019-05-26 08:14:08 +03:00
|
|
|
(pure:m q.u.r.httr)
|
|
|
|
::
|
|
|
|
:: Parse cord to json
|
|
|
|
::
|
|
|
|
++ parse-json
|
|
|
|
|= =cord
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,json)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
|
|
|
=/ json=(unit json) (de-json:html cord)
|
|
|
|
?~ json
|
2019-06-01 00:44:47 +03:00
|
|
|
(async-fail %json-parse-error ~)
|
2019-05-26 08:14:08 +03:00
|
|
|
(pure:m u.json)
|
|
|
|
::
|
|
|
|
:: Fetch json at given url
|
|
|
|
::
|
|
|
|
++ fetch-json
|
|
|
|
|= url=tape
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,json)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
|
|
|
=/ =hiss:eyre
|
|
|
|
:* purl=(scan url auri:de-purl:html)
|
|
|
|
meth=%get
|
|
|
|
math=~
|
|
|
|
body=~
|
|
|
|
==
|
|
|
|
;< ~ bind:m (send-hiss hiss)
|
|
|
|
;< =httr:eyre bind:m take-sigh
|
|
|
|
;< =cord bind:m (extract-httr-body httr)
|
|
|
|
(parse-json cord)
|
|
|
|
::
|
|
|
|
:: ----
|
|
|
|
::
|
2019-06-26 08:35:46 +03:00
|
|
|
:: Incoming HTTP requests
|
|
|
|
::
|
|
|
|
++ bind-route-raw
|
2019-07-04 09:09:44 +03:00
|
|
|
|= [=binding:eyre =term]
|
2019-06-26 08:35:46 +03:00
|
|
|
=/ m (async ,~)
|
|
|
|
^- form:m
|
|
|
|
(send-raw-card [%connect / binding term])
|
|
|
|
::
|
|
|
|
++ take-bound
|
|
|
|
=/ m (async ?)
|
|
|
|
^- form:m
|
|
|
|
|= =async-input
|
|
|
|
:^ ~ ~ ~
|
|
|
|
?~ in.async-input
|
|
|
|
[%wait ~]
|
|
|
|
=* sign sign.u.in.async-input
|
|
|
|
?. ?=(%bound -.sign)
|
|
|
|
[%fail %expected-bound >got=-.sign< ~]
|
|
|
|
[%done success.sign]
|
|
|
|
::
|
|
|
|
++ bind-route
|
2019-07-04 09:09:44 +03:00
|
|
|
|= [=binding:eyre =term]
|
2019-06-26 08:35:46 +03:00
|
|
|
=/ m (async ?)
|
|
|
|
^- form:m
|
|
|
|
;< ~ bind:m (bind-route-raw binding term)
|
|
|
|
take-bound
|
|
|
|
::
|
|
|
|
:: ----
|
|
|
|
::
|
2019-06-05 01:17:45 +03:00
|
|
|
:: Identity is immutable
|
|
|
|
::
|
2019-06-21 21:00:50 +03:00
|
|
|
:: XX should be statefully cycled
|
|
|
|
::
|
2019-06-05 01:17:45 +03:00
|
|
|
++ get-identity
|
|
|
|
=/ m (async ,@p)
|
|
|
|
^- form:m
|
|
|
|
|= =async-input
|
|
|
|
[~ ~ ~ %done our.bowl.async-input]
|
|
|
|
::
|
|
|
|
:: Entropy is always increasing
|
|
|
|
::
|
|
|
|
++ get-entropy
|
|
|
|
=/ m (async ,@uvJ)
|
|
|
|
^- form:m
|
|
|
|
|= =async-input
|
|
|
|
[~ ~ ~ %done eny.bowl.async-input]
|
|
|
|
::
|
|
|
|
:: ----
|
|
|
|
::
|
2019-05-26 08:14:08 +03:00
|
|
|
:: Time is what keeps everything from happening at once
|
|
|
|
::
|
|
|
|
++ get-time
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,@da)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-06-01 00:44:47 +03:00
|
|
|
|= =async-input
|
|
|
|
[~ ~ ~ %done now.bowl.async-input]
|
2019-05-26 08:14:08 +03:00
|
|
|
::
|
|
|
|
:: Set a timer
|
|
|
|
::
|
|
|
|
++ send-wait
|
|
|
|
|= at=@da
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-05-29 03:01:18 +03:00
|
|
|
;< ~ bind:m (send-raw-card %wait /note/(scot %da at) at)
|
2019-05-26 08:14:08 +03:00
|
|
|
(set-raw-contract & %wait at)
|
|
|
|
::
|
|
|
|
:: Wait until we get a wake event
|
|
|
|
::
|
|
|
|
++ take-wake-raw
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,@da)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
2019-06-01 00:44:47 +03:00
|
|
|
|= =async-input
|
2019-05-26 08:14:08 +03:00
|
|
|
:^ ~ ~ ~
|
2019-06-01 00:44:47 +03:00
|
|
|
?~ in.async-input
|
2019-05-26 08:14:08 +03:00
|
|
|
[%wait ~]
|
2019-06-01 00:44:47 +03:00
|
|
|
?. ?=(%wake -.sign.u.in.async-input)
|
|
|
|
[%fail %expected-wake >got=-.sign.u.in.async-input< ~]
|
|
|
|
?~ wire.u.in.async-input
|
2019-05-26 08:14:08 +03:00
|
|
|
[%fail %expected-wake-time ~]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ at=(unit @da) (slaw %da i.wire.u.in.async-input)
|
2019-05-26 08:14:08 +03:00
|
|
|
?~ at
|
|
|
|
[%fail %expected-wake-time-da >wire< ~]
|
|
|
|
[%done u.at]
|
|
|
|
::
|
|
|
|
:: Wait until we get a wake event and unset contract
|
|
|
|
::
|
|
|
|
++ take-wake
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
|
|
|
;< at=@da bind:m take-wake-raw
|
|
|
|
(set-raw-contract | %wait at)
|
|
|
|
::
|
|
|
|
:: Wait until time
|
|
|
|
::
|
|
|
|
++ wait
|
|
|
|
|= until=@da
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-26 08:14:08 +03:00
|
|
|
^- form:m
|
|
|
|
;< ~ bind:m (send-wait until)
|
|
|
|
take-wake
|
|
|
|
::
|
2019-05-29 03:01:18 +03:00
|
|
|
:: Wait until time then start new computation
|
|
|
|
::
|
|
|
|
++ wait-effect
|
|
|
|
|= until=@da
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-29 03:01:18 +03:00
|
|
|
^- form:m
|
|
|
|
(send-effect %wait /effect/(scot %da until) until)
|
|
|
|
::
|
2019-05-26 08:14:08 +03:00
|
|
|
:: Cancel computation if not done by time
|
|
|
|
::
|
|
|
|
++ set-timeout
|
|
|
|
|* computation-result=mold
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,computation-result)
|
2019-05-26 08:14:08 +03:00
|
|
|
|= [when=@da computation=form:m]
|
|
|
|
^- form:m
|
|
|
|
;< ~ bind:m (send-wait when)
|
2019-06-01 00:44:47 +03:00
|
|
|
|= =async-input
|
2019-05-26 08:14:08 +03:00
|
|
|
=* loop $
|
2019-06-01 00:44:47 +03:00
|
|
|
?: ?& ?=([~ * %wake *] in.async-input)
|
|
|
|
=(/(scot %da when) wire.u.in.async-input)
|
2019-05-26 08:14:08 +03:00
|
|
|
==
|
2019-06-21 10:35:07 +03:00
|
|
|
[~ ~ (my [[%wait when] [%lose ~]] ~) %fail %async-timeout ~]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ c-res (computation async-input)
|
2019-05-26 08:14:08 +03:00
|
|
|
?. ?=(%cont -.next.c-res)
|
|
|
|
c-res
|
|
|
|
c-res(self.next ..loop(computation self.next.c-res))
|
2019-05-28 23:23:06 +03:00
|
|
|
::
|
|
|
|
:: ----
|
|
|
|
::
|
|
|
|
:: Apps
|
|
|
|
::
|
|
|
|
++ poke-app
|
|
|
|
|= [[her=ship app=term] =poke-data]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-28 23:23:06 +03:00
|
|
|
^- form:m
|
2019-06-05 01:54:45 +03:00
|
|
|
=/ =wire /(scot %p her)/[app]
|
|
|
|
(send-effect %poke wire [her app] poke-data)
|
2019-05-29 01:38:14 +03:00
|
|
|
::
|
|
|
|
++ peer-app
|
|
|
|
|= [[her=ship app=term] =path]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-29 01:38:14 +03:00
|
|
|
^- form:m
|
|
|
|
=/ =wire (weld /(scot %p her)/[app] path)
|
|
|
|
(send-effect %peer wire [her app] path)
|
|
|
|
::
|
|
|
|
++ pull-app
|
|
|
|
|= [[her=ship app=term] =path]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-29 01:38:14 +03:00
|
|
|
^- form:m
|
|
|
|
=/ =wire (weld /(scot %p her)/[app] path)
|
|
|
|
(send-effect %pull wire [her app] ~)
|
|
|
|
::
|
|
|
|
:: ----
|
|
|
|
::
|
|
|
|
:: Handle subscriptions
|
|
|
|
::
|
|
|
|
:: Get bones at particular path; for internal use only
|
|
|
|
::
|
|
|
|
++ get-bones-on-path
|
|
|
|
|= =the=path
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,(list bone))
|
2019-05-29 01:38:14 +03:00
|
|
|
^- form:m
|
2019-06-01 00:44:47 +03:00
|
|
|
|= =async-input
|
2019-05-29 01:38:14 +03:00
|
|
|
:^ ~ ~ ~
|
|
|
|
:- %done
|
2019-06-01 00:44:47 +03:00
|
|
|
%+ murn ~(tap by sup.bowl.async-input)
|
2019-05-29 01:38:14 +03:00
|
|
|
|= [ost=bone her=ship =sub=path]
|
|
|
|
^- (unit bone)
|
|
|
|
?. =(the-path sub-path)
|
|
|
|
~
|
|
|
|
`ost
|
|
|
|
::
|
|
|
|
:: Give a result to subscribers on particular path
|
|
|
|
::
|
|
|
|
++ give-result
|
|
|
|
|= [=path =out-peer-data]
|
2019-06-01 00:44:47 +03:00
|
|
|
=/ m (async ,~)
|
2019-05-29 01:38:14 +03:00
|
|
|
^- form:m
|
|
|
|
;< bones=(list bone) bind:m (get-bones-on-path path)
|
|
|
|
|- ^- form:m
|
|
|
|
=* loop $
|
|
|
|
?~ bones
|
|
|
|
(pure:m ~)
|
|
|
|
;< ~ bind:m (send-effect-on-bone i.bones %diff out-peer-data)
|
|
|
|
loop(bones t.bones)
|
2019-06-05 04:21:42 +03:00
|
|
|
::
|
|
|
|
:: ----
|
|
|
|
::
|
|
|
|
:: Handle domains
|
|
|
|
::
|
|
|
|
++ install-domain
|
|
|
|
|= =turf
|
|
|
|
=/ m (async ,~)
|
|
|
|
^- form:m
|
|
|
|
(send-effect %rule / %turf %put turf)
|
2019-05-26 08:14:08 +03:00
|
|
|
--
|