Object Run
Executing objects as tasks.
#[type]
Task: {
ok: false
result: null
config: {
endpoint: "https://myendpoint"
schema: {
// some schema to apply to the result
}
}
#[run]
fn exec() {
const res = await Http.fetch(self.config.endpoint);
const result = new {};
parse(res.remove("text"), result, "json");
self.ok = self.config.schema.schemafy(result);
self.result = result;
}
}
#[main]
fn main() {
const task = new Task {
config: new {
endpoint: 'https://restcountries.com/v3.1/region/europe'
}
};
task.run();
assert(task.ok);
for (const country in task.result.field) {
pln(country.name);
}
}Ordering
Running Fields
Last updated