Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The rule creates the new child pico (shown by a green arrow), and sends it a sequence of events:

  1. the engine_ui:setup event, fielded by the engine-ui ruleset which creates a new channel suitable for use by the UI, and returns that channel’s ID which is bound to the name newUiECI

  2. the wrangler:pico_created event, fielded by a wrangler rule, which saves the name, and installs the subscription ruleset (shown by a green arrow)

  3. the engine_ui:box event, fielded by the engine-ui ruleset which stores away the name and background color so that the new pico can be correctly rendered in the developer UI

Finally that rule raises a wrangler:new_child_created event for the parent pico. And, the child pico, after it has finished with its work, sends a wrangler:child_initialized event back to the parent pico.

...

Events to which wrangler reacts

event

raised by

attributes

wrangler:new_child_request

UI or KRL application

required name, optional backgroundColor, optional additional attributes to be passed through

wrangler:pico_created

Wrangler (not for use by KRL programmers) to the new child pico

name (of child pico)

wrangler:child_deletion_request

UI or KRL application

required eci of family channel from parent to child

wrangler:ready_for_deletion

KRL application

none (implicit)

Events which wrangler raises

event

to/from

attributes

wrangler:new_child_created

internal to parent pico

passed through from initialwrangler:new_child_request

and the eci of the new child pico

wrangler:pico_initialized

internal to child pico

wrangler:child_initialized

from child pico to parent pico

wrangler:child_deleted

internal to parent pico

passed through from initial wrangler:child_deletion_request

The KRL programmer may choose to write rules that react to these raised events.

...

A pico can have as many inbound channels as it needs. See Managing Channels for more information. A pico can only create and delete channels for itself.

...

For example, this KRL code creates a channel when the app_section_collection ruleset is installed into a pico (see the Pico to Pico Subscriptions Lesson for context):

Code Block
ruleset app_section_collection {
  ...
  global {
    ...
    tags = ["app_section_collection"]
    eventPolicy = {
      "allow": [ { "domain": "section", "name": "*" }, ],
      "deny": []
    }
    queryPolicy = {
      "allow": [ { "rid": meta:rid, "name": "*" } ],
      "deny": []
    }
  }
  rule initialize_section_collection_pico {
    select when wrangler ruleset_installed
      where event:attr("rids") >< meta:rid
    if ent:section_collection_pico_eci.isnull() then
      wrangler:createChannel(tags,eventPolicy,queryPolicy) setting(channel)
    fired {
      ent:section_collection_pico_eci := channel{"id"}
      ent:sections := {}
    }
  }
  ...
}

...

Note in line 5, the use of the array operator head() to convert the array of channels returned by the wrangler:channels() function into a single channel map.

...

Wrangler reacts to the wrangler:install_ruleset_request to install a specified ruleset into the pico. It takes two forms:

  1. When given one attribute, url, it installs the KRL code at that URL into the pico.

  2. When given attributes absoluteURL and rid, it resolves a URL substituting the given rid as a KRL filename based on the absoluteURL. It installs the KRL code at that URL into the pico.

The second form is useful when the KRL programmer has several rulesets which operate together in a pico-based system. It allows the bootstrapping of the system by installing a single ruleset which then installs all of the others using simple RIDs instead of absolute URLs.

Both forms take a config attribute that contains a map of the configuration parameters for the ruleset.

In either form, wrangler raises the wrangler:ruleset_installed event, passing rids, an array of RIDs containing the RID of the ruleset just installed.

...

For example, wrangler:rulesetMeta(“hello_world”) (which refers to the ruleset shown in the Pico Engine Quickstart page), would return this map:

...

picoQuery() is mainly used to programmatically call functions inside of other picos from inside a rule. However, deadlocks are possible due to its synchronous nature (e.g. do not let two picos query each other simultaneously). See Accessing a Function Shared by Another Pico for more information.

Parameters

Optional parameters are italicized.

Parameter

Datatype

Description

eci

String

The ECI to send the query to

mod

String

The RID of the ruleset to send the query to

func

String

The name of the function to query

params

Map

The parameters to be passed to the function on the target pico. Given as a map with parameter name as the key and argument as the value.

_host

String

The host of the pico engine being queried.
Note this must include protocol (http:// or https://) being used and port number if not 80.
For example "http://localhost:3000", which also is the default.

_path

String

The sub path of the url which does not include mod or func.
For example "/sky/cloud/", which also is the default.

_root_url

String

The entire URL except eci, mod , func.
For example, dependent on _host and _path is
"http://localhost:3000/sky/cloud/", which also is the default. Defaults to meta:host (the pico engine itself).

If _host is missing or the same as the result returned by meta:host, picoQuery() will use ctx:query() instead of HTTP.

...

Failure: a map of error information which contains the error and other optional information:

Code Block
{
    "error":"general error message",
    "picoQueryError":"The value of the 'error key', if it exists, of the function results"
    "picoQueryErrorMsg":"The value of the 'error_str', if it exists, of the function results"
    "picoQueryReturnValue":"The function call results"
}
Info

This map represents a breaking change. The previous map returned skyQueryError instead of picoQueryError, for example. If your code depends on these, you will need to update to use the new error map.

Example

Code Block
pre {
  eci = eci_to_other_pico;
  args = {"arg1": val1, "arg2": val2};
  answer = wrangler:picoQuery(eci,"my.ruleset.id","myFunction",{}.put(args))
ƒ
;
}
if answer{"error"}.isnull() then noop(); // Check that it did not return an error
fired {
  // process using answer
}