Strandio Reference

Documented below are the many useful functions in the /lib/strandio.hoon helper library.

Send Cards

send-raw-cards

Send 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 a single $card.

Accepts

A card:agent:gall

Produces

~

Source

Example


Bowl

get-bowl

Get the bowl.

Accepts

Nothing.

Produces

A bowl:rand.

Source

Example


+get-beak

Get the beak.

Accepts

Nothing.

Produces

A $beak.

Source

Example


get-time

Get the current date-time.

Accepts

Nothing.

Produces

A @da.

Source

Example


get-our

Get our ship.

Accepts

Nothing.

Produces

A @p.

Source

Example


get-entropy

Get some entropy.

Accepts

Nothing.

Produces

A @uvJ.

Source

Example


Misc

install-domain

Install a domain in Eyre, triggering the setup of an SSL certificate.

Accepts

A $turf.

Produces

~

Source

Example


check-online

Require 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

Wait for a sign from Arvo.

Accepts

Nothing.

Produces

A pair of [wire sign-arvo].

Source

Example


Pokes

+poke

Poke 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

Poke 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

Poke 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 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 a poke ack on the given wire.

If the ack is a nack, the strand fails.

Accepts

A $wire.

Produces

~

Source

Example


take-poke

Wait for a poke with a particular mark.

Accepts

A $mark.

Produces

A $vase.

Source

Example


Subscriptions

watch

Watch 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

Subscribe 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

Subscribe 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

Leave a subscription.

Accepts

A pair of [=wire =dock] where $dock is the ship and agent in question.

Produces

~

Source

Example


leave-our

Unsubscribe from a local agent.

Accepts

A pair of [=wire =term] where $term is the local agent.

Produces

~

Source

Example


rewatch

Resubscribe 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

Wait 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

Wait for a subscription update on a wire.

Accepts

The $wire you want to listen on.

Produces

A $cage.

Source

Example


take-kick

Wait for a subscription close.

Accepts

The $wire you want to listen on.

Produces

~

Source

Example


take-watch-ack

Take 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

Wait for a subscription request.

Accepts

Nothing.

Produces

The subscription $path.

Source

Example


Scries

+scry

Scry 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

Make 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

Wait for a remote scry result on a particular wire.

Accepts

A $wire.

Produces

A [spar:ames (unit roar:ames)]

Source

Example


Time

wait

Send 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

Wait for a relative amount of time.

Accepts

A @dr.

Produces

~

Source

Example


send-wait

Send Behn a %wait but don't wait for the %wake.

Accepts

A @da.

Produces

~

Source

Example


set-timeout

Make 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

Wait 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

Retry 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

Wait 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

Rewrite 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-tag and 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

Make an HTTP request via Iris, but don't wait for the response.

Accepts

A request:http.

Produces

~

Source

Example


send-cancel-request

Cancel 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 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

A client-response:iris.

Source

Example


take-maybe-sigh

Take 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 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 body from an HTTP response.

Accepts

A client-response:iris

Produces

A $cord.

Source


fetch-cord

Get the HTTP response body from a URL.

Accepts

The URL in a $tape.

Produces

A $cord of the response body.

Source

Example


fetch-json

Get some JSON from a URL.

Accepts

The URL as a $tape.

Produces

A $json structure.

Source

Example


hiss-request

Make 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 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 a source file at the specified $beam, crashing if it fails.

Accepts

A $beam.

Produces

A $vase.

Source

Example


build-mark

Build a dynamic mark core from file.

Accepts

A pair of [beak mark].

Produces

A $dais:clay

Source

Example


+build-tube

Build 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 a static mark core from file.

Accepts

A pair of [beak mark].

Produces

A $vase.

Source

Example


+build-cast

Build 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

Evaluate 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

Raw read from Clay.

Accepts

A pair of $ship and $riff:clay.

Produces

A $riot:clay.

Source

Example


+read-file

Read a file from Clay.

Accepts

A $beam.

Produces

A $cage.

Source

Example


check-for-file

Check 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

Get a list of all files in the given Clay directory.

Accepts

A $beam.

Produces

A (list path).

Source

Example


take-writ

Take a Clay read result.

Accepts

The $wire to listen on.

Produces

A $riot:clay.

Source

Example


Main Loop

ignore

Try 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

Convert 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

A main-loop can be used for three things:

  1. create a loop.

  2. try the same input against multiple strands.

  3. Queue input on %skip and 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

main-loop code

Example

See the separate main-loop example or the +echo example below.


+echo

Echo 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

Send a wrapped Dill task to Dill.

Accepts

A $flog:dill.

Produces

~

Source

Example


flog-text

Print a message to the terminal via Dill.

Accepts

A $tape.

Produces

~

Source

Example


flog-tang

Print a $tang to the terminal via Dill.

Accepts

A $tang

Produces

~

Source

Example


+trace

Slog a $tang to the terminal.

Accepts

A $tang.

Produces

~

Source

Example


app-message

Print 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

Run 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 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 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 /ted of the given desk.

  • $vase: the start argument.

Produces

A tid:spider, the ID of the child thread.

Source

Example


thread-result

Type definition of a thread result.

Source


await-thread

Start 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

A thread-result

Source

Example


Last updated