Strandio Reference
Documented below are the many useful functions in the /lib/strandio.hoon helper library.
Send Cards
send-raw-cards
send-raw-cardsSend a list of $cards.
Accepts
A (list card:agent:gall).
Produces
~
Source
++ send-raw-cards
|= cards=(list =card:agent:gall)
=/ m (strand ,~)
^- form:m
|= strand-input:strand
[cards %done ~]Example
send-raw-card
send-raw-cardSend a single $card.
Accepts
A card:agent:gall
Produces
~
Source
Example
Bowl
get-bowl
get-bowlGet the bowl.
Accepts
Nothing.
Produces
A bowl:rand.
Source
Example
+get-beak
+get-beakGet the beak.
Accepts
Nothing.
Produces
A $beak.
Source
Example
get-time
get-timeGet the current date-time.
Accepts
Nothing.
Produces
A @da.
Source
Example
get-our
get-ourGet our ship.
Accepts
Nothing.
Produces
A @p.
Source
Example
get-entropy
get-entropyGet some entropy.
Accepts
Nothing.
Produces
A @uvJ.
Source
Example
Misc
install-domain
install-domainInstall a domain in Eyre, triggering the setup of an SSL certificate.
Accepts
A $turf.
Produces
~
Source
Example
check-online
check-onlineRequire that a peer respond before timeout.
The peer is pinged with a "hi" and must ack the poke before the timeout.
Accepts
A pair of [ship @dr]. The @dr is the amount of time the peer has to respond before failure.
Produces
~
Source
Example
take-sign-arvo
take-sign-arvoWait for a sign from Arvo.
Accepts
Nothing.
Produces
A pair of [wire sign-arvo].
Source
Example
Pokes
+poke
+pokePoke an agent, then await a positive ack.
Accepts
A pair of [dock cage], where the $dock is the ship and agent you want to poke, and the $cage is the data.
Produces
~
Source
Example
raw-poke
raw-pokePoke an agent then await a (n)ack.
This doesn't care whether the ack is positive or negative, unlike the ordinary poke.
Accepts
A pair of [dock cage], where the $dock is the ship and agent to poke, and the $cage is the data.
Produces
~
Source
Example
raw-poke-our
raw-poke-ourPoke a local agent then await a (n)ack.
This doesn't care whether the ack is positive or negative, unlike the ordinary poke-our.
Accepts
A pair of [app=term =cage], where app is the local agent to poke and $cage is the data.
Produces
~
Source
Example
poke-our
poke-ourPoke a local agent then await an ack.
Note this fails if it gets a nack back.
Accepts
A pair of [=term =cage] where $term is the name of a local agent and $cage is the data.
Produces
~
Source
Example
take-poke-ack
take-poke-ackTake a poke ack on the given wire.
If the ack is a nack, the strand fails.
Accepts
A $wire.
Produces
~
Source
Example
take-poke
take-pokeWait for a poke with a particular mark.
Accepts
A $mark.
Produces
A $vase.
Source
Example
Subscriptions
watch
watchWatch a subscription path on an agent, then await a positive watch ack.
Note this fails if it gets a watch nack back.
Accepts
A triple of [=wire =dock =path] where $dock is the ship and agent, and $path is the subscription path.
Produces
~
Source
Example
watch-one
watch-oneSubscribe to a watch path on an agent, take a single fact, then await a kick.
Accepts
A triple of [=wire =dock =path] where $dock is a ship and agent, and $path is the subscription path.
Produces
The $cage of the received fact.
Source
Example
watch-our
watch-ourSubscribe to a watch path on a local agent, then wait for a positive ack.
This will fail if it gets a watch nack.
Accepts
A triple of [=wire =term =path] where $term is the name of the agent and $path is the subscription path.
Produces
~
Source
Example
leave
leaveLeave a subscription.
Accepts
A pair of [=wire =dock] where $dock is the ship and agent in question.
Produces
~
Source
Example
leave-our
leave-ourUnsubscribe from a local agent.
Accepts
A pair of [=wire =term] where $term is the local agent.
Produces
~
Source
Example
rewatch
rewatchResubscribe on kick.
This waits for a kick on a given wire, then rewatches the given ship, agent and path on the same wire. It then waits for a positive watch ack.
Accepts
A triple of [=wire =dock =path] where $dock is the ship and agent, and $path is the subscription path.
Produces
~
Source
Exmaple
take-fact-prefix
take-fact-prefixWait for a subscription update on a wire.
Accepts
A $wire as the prefix of what you expect. E.g. if /foo is given, a fact with a wire of /foo, /foo/bar, /foo/bar/baz, etc, will be accepted.
Produces
A cell of [wire cage].
Source
Example
take-fact
take-factWait for a subscription update on a wire.
Accepts
The $wire you want to listen on.
Produces
A $cage.
Source
Example
take-kick
take-kickWait for a subscription close.
Accepts
The $wire you want to listen on.
Produces
~
Source
Example
take-watch-ack
take-watch-ackTake a watch ack on a given wire.
If the watch ack is a nack, the strand fails.
Accepts
A $wire.
Produces
~
Source
Example
take-watch
take-watchWait for a subscription request.
Accepts
Nothing.
Produces
The subscription $path.
Source
Example
Scries
+scry
+scryScry an agent or vane.
Accepts
A pair of [=mold =path] where $mold is the type returned and $path has the following format:
The strand implicitly fills in our and now in the beak.
Produces
Data of the type produced by the mold you specified.
Source
Example
keen
keenMake a remote scry request.
Note this doesn't wait for a response, you'd have to use a separate take-tune strand to receive the result.
Accept
A pair of [=wire =spar:ames].
Produces
~
Source
Example
take-tune
take-tuneWait for a remote scry result on a particular wire.
Accepts
A $wire.
Produces
A [spar:ames (unit roar:ames)]
Source
Example
Time
wait
waitSend a %wait to Behn and wait for the %wake.
Note there's also sleep to wait for a relative amount of time rather than having to specify an absolute time.
Accepts
A @da of when the timer should fire.
Produces
~
Source
Example
sleep
sleepWait for a relative amount of time.
Accepts
A @dr.
Produces
~
Source
Example
send-wait
send-waitSend Behn a %wait but don't wait for the %wake.
Accepts
A @da.
Produces
~
Source
Example
set-timeout
set-timeoutMake a strand fail if it takes too long.
Accepts
This takes the $mold produced but the strand you're timing, and produces a gate. The gate takes a pair of the @dr timeout and the strand being timed.
Produces
Data of the type produced by the strand being timed.
Source
Example
take-wake
take-wakeWait for a wake from Behn.
This is meant for internal use by wait, you'd not typically use it directly.
Accepts
A (unit @da). If the unit is non-null, it'll only accept a %wake whose wire is of the form /wait/(scot %da the-given-time). If the unit is null, it'll accept a %wake with a wire of /wait/(scot %da any-time).
Produces
~
Source
Example
Errors
retry
retryRetry a strand that produces a +unit if the +unit is null, with a backoff.
Accepts
retry first takes a result=mold of the return type and produces a gate. That gate takes two arguments:
crash-after=(unit @ud): the number of tries before failing.computation: A strand that produces a(unit result).
Produces
The type of .result.
Source
Example
backoff
backoffWait for increasing amounts of time with each try.
Accepts
A pair of [try=@ud limit=@dr], specifying the current try count and the maximum amount of time to wait.
Produces
~
Source
map-err
map-errRewrite a strand failure error.
Accepts
This function takes the return $mold of the strand in question as its argument and returns a gate that takes two arguments:
.f: a gate that takes a[term tang]and produces a[term tang]. This is the%error-tagand stack trace of the failure you're rewriting.computation: the strand whose errors you're rewriting.
See the example below for usage.
Produces
Data of the type produced by the strand in question.
Source
Example
HTTP
send-request
send-requestMake an HTTP request via Iris, but don't wait for the response.
Accepts
A request:http.
Produces
~
Source
Example
send-cancel-request
send-cancel-requestCancel a previous Iris HTTP request.
This sends it on the /request wire used by send-request. It won't work if the original request was on a different wire.
Accepts
Nothing.
Produces
~
Source
Example
take-client-response
take-client-responseTake the HTTP response from a previous HTTP request made with send-request.
This listens on the /request wire, it won't work if you're made a request on a different wire.
Accepts
Nothing.
Produces
Source
Example
take-maybe-sigh
take-maybe-sighTake a unitized raw HTTP response.
Accepts
Nothing
Produces
A (unit httr:eyre). The +unit is null if we failed to receive a response.
Source
Example
take-maybe-response
take-maybe-responseTake a unitized HTTP response.
Accepts
Nothing
Produces
A (unit client-response:iris). The +unit is null if we failed to receive a response.
Source
Example
extract-body
extract-bodyExtract body from an HTTP response.
Accepts
A client-response:iris
Produces
A $cord.
Source
fetch-cord
fetch-cordGet the HTTP response body from a URL.
Accepts
The URL in a $tape.
Produces
A $cord of the response body.
Source
Example
fetch-json
fetch-jsonGet some JSON from a URL.
Accepts
The URL as a $tape.
Produces
A $json structure.
Source
Example
hiss-request
hiss-requestMake a raw HTTP request, take a raw response.
Accepts
$hiss:eyre
Produces
A (unit httr:eyre). The +unit is null if we failed to receive a response.
Source
Example
Build
+build-file
+build-fileBuild a source file at the specified $beam.
Accepts
A $beam.
Produces
A (unit vase). The $vase contains the compiled file, the +unit is null if it failed.
Source
Example
build-file-hard
build-file-hardBuild a source file at the specified $beam, crashing if it fails.
Accepts
A $beam.
Produces
A $vase.
Source
Example
build-mark
build-markBuild a dynamic mark core from file.
Accepts
A pair of [beak mark].
Produces
A $dais:clay
Source
Example
+build-tube
+build-tubeBuild a dynamic mark conversion gate from file.
Accepts
A pair of [beak mars:clay]. A $mars is a pair of the from and to mark.
Produces
A $tube:clay
Source
Example
+build-nave
+build-naveBuild a static mark core from file.
Accepts
A pair of [beak mark].
Produces
A $vase.
Source
Example
+build-cast
+build-castBuild a static mark conversion gate from file.
Accepts
A pair of [beak mars:clay]. A $mars is a pair of the from mark and to mark.
Source
Example
eval-hoon
eval-hoonEvaluate some hoon and produce the result.
Accepts
A pair of [gen=hoon bez=(list beam)]. The .gen argument is the hoon to be evaluated. If bez is empty, it will be evaluated against the standard ..zuse subject. If a list of $beams are provided in bez, each one will be read from Clay, build, and pinned to the head of the subject, before .gen is evaluated against it.
Produces
A $vase of the result.
Source
Example
Clay
warp
warpRaw read from Clay.
Accepts
A pair of $ship and $riff:clay.
Produces
A $riot:clay.
Source
Example
+read-file
+read-fileRead a file from Clay.
Accepts
A $beam.
Produces
A $cage.
Source
Example
check-for-file
check-for-fileCheck for the existence of a file in Clay.
Accepts
A $beam.
Produces
A ? which is %.y if the file exists, and %.n if not.
Source
Example
list-tree
list-treeGet a list of all files in the given Clay directory.
Accepts
A $beam.
Produces
A (list path).
Source
Example
take-writ
take-writTake a Clay read result.
Accepts
The $wire to listen on.
Produces
A $riot:clay.
Source
Example
Main Loop
ignore
ignoreTry next on failure.
This produces a failure with an %ignore status, which main-loop uses to skip the strand and try the next one. This is of little use outside the context of a main-loop.
Accepts
Nothing.
Produces
Nothing.
Source
handle
handleConvert skips to %ignore failures.
This tells main-loop to try the next strand on skips. This would not be used outside of a main-loop.
Accepts
+handle takes a mold and produces a gate that takes another strand.
Produces
Data of the type produced by the given mold.
Source
Example
main-loop
main-loopA main-loop can be used for three things:
create a loop.
try the same input against multiple strands.
Queue input on
%skipand then dequeue from the beginning on%done.
Accepts
It first accepts a $mold, specifying the return type, and produces a gate. The gate produced takes a +list of gates that take an argument of the specified $mold, and produce the +form of a +strand of that mold.
Produces
Data of the type produced by the given $mold.
Source
Example
See the separate main-loop example or the +echo example below.
+echo
+echoEcho a given message to the terminal every 2 seconds until told to stop.
Accepts
This strand takes nothing directly, but expects a poke with a $mark of %echo and vase containing a $tape with the message to echo. To finish, it expects a poke with a $mark of %over.
Produces
~
Source
Printing
flog
flogSend a wrapped Dill task to Dill.
Accepts
A $flog:dill.
Produces
~
Source
Example
flog-text
flog-textPrint a message to the terminal via Dill.
Accepts
A $tape.
Produces
~
Source
Example
flog-tang
flog-tangPrint a $tang to the terminal via Dill.
Accepts
A $tang
Produces
~
Source
Example
+trace
+traceSlog a $tang to the terminal.
Accepts
A $tang.
Produces
~
Source
Example
app-message
app-messagePrint a message to the terminal tagged with an app name, like:
Then, optionally, print a $tang.
Accepts
A triple of [term cord tang]. The $term is the app name, the $cord is the message, and the $tang is any traceback.
Produces
~
Source
Example
Threads
send-thread
send-threadRun an inline thread via Khan.
Accepts
A triple of:
$bear:khan: desk or beak.$shed:khan: the thread itself.$wire: the wire for responses from Khan.
Produces
~
Source
start-thread
start-threadStart a child thread.
Accepts
A $term, the name of a thread in /ted of this desk.
Produces
A $tid:spider, the ID of the child thread.
Source
Example
start-thread-with-args
start-thread-with-argsStart a child thread with arguments.
Accepts
A triple of:
$beak: the ship/desk/case where the thread is located.$term: the name of the thread in/tedof the given desk.$vase: the start argument.
Produces
A tid:spider, the ID of the child thread.
Source
Example
thread-result
thread-resultType definition of a thread result.
Source
await-thread
await-threadStart a thread with an argument, then await its result.
Accepts
A pair of [term vase] where $term is the name of a thread in /ted of this desk, and $vase contains the start argument.
Produces
Source
Example
Last updated