// Code generated by goalchemy. DO NOT EDIT.
// @ts-nocheck
import * as rt from "./rt/index.ts";
import { $types, Buffer, Builder, Decoder, Encoder, InvalidUnmarshalError, LimitedReader, MarshalerError, NumError, OffsetWriter, Replacer, SectionReader, SyntaxError, Task, UnmarshalTypeError, UnsupportedValueError, bytes_Reader, clone$array_128_bool, clone$array_24_uint8, clone$array_2_string, clone$array_4_int, clone$array_64_uint8, decimal, decodeState, discard, encodeState, encodingError, eq$array_128_bool, eq$array_24_uint8, eq$array_2_string, eq$array_4_int, eq$array_64_uint8, fault, field, floatInfo, floatParts, ioError, joinError, key$array_128_bool, key$array_24_uint8, key$array_2_string, key$array_4_int, key$array_64_uint8, keyed, leftCheat, multiReader, multiWriter, never_2, nopCloser, reverse, scanner, set$array_128_bool, set$array_24_uint8, set$array_2_string, set$array_4_int, set$array_64_uint8, strings_Reader, teeReader, typeInfo, zero$array_128_bool, zero$array_24_uint8, zero$array_2_string, zero$array_4_int, zero$array_64_uint8 } from "./shared.ts";
import * as $module_pkg_json_8cc9496285d7f743 from "./pkg_json_8cc9496285d7f743.ts";
export const $globals = {
};
export async function fetchTasks(url: any, _t: rt.Task): Promise<any> {
let _1, _2, status, body, err, _6, _7, _8, _9, _10, _16, tasks, _18: any;
_1 = rt.NIL;
_2 = null;
_6 = rt.stdContextBackground();
rt.libHttpDo(_t, _6, "GET", url, rt.NIL, rt.BYTE_NIL, 1048576n, 5000n);
if (_t.blocked) await rt.wait(_t);
_7 = _t.rv[0];
_8 = _t.rv[1];
_9 = _t.rv[2];
_10 = _t.rv[3];
status = _7;
body = _9;
err = _10;
if (!rt.ifaceEq(err, null)) {
_1 = rt.NIL;
_2 = err;
return [_1, _2];
}
if (!(status === 200n)) {
_16 = rt.stdErrorsNew("unexpected HTTP status");
_1 = rt.NIL;
_2 = _16;
return [_1, _2];
}
tasks = new rt.Cell(rt.NIL);
_18 = tasks;
err = $module_pkg_json_8cc9496285d7f743.unmarshalTyped(body, rt.box($types.TD$pointer_slice_main_Task, _18), $module_pkg_json_8cc9496285d7f743._ddesc_main_Task(), _18 === null, "");
_1 = tasks.v;
_2 = err;
return [_1, _2];
}
(fetchTasks as any).$fid = 516;
export async function main(_t: rt.Task): Promise<any> {
let tasks, err, _2, _3, completed, _8, _9, _10, task: any;
[_2, _3] = await fetchTasks("https://jsonplaceholder.typicode.com/todos", _t);
tasks = _2;
err = _3;
if (!rt.ifaceEq(err, null)) {
rt.print(["Could not load tasks:", rt.ichk(err).t.methods["Error"](err.v)], true);
return undefined;
}
completed = 0n;
_10 = tasks;
_9 = BigInt(_10.l);
_8 = 0n;
while (_8 < _9) {
task = rt.sget(_10, _8).$clone();
if (task.f$Completed) {
completed = rt.add_i64(completed, 1n);
} else {
rt.print(["To do:", task.f$Title], true);
}
_8 = rt.add_i64(_8, 1n);
}
rt.print(["Completed:", completed, "of", BigInt(tasks.l)], true);
return undefined;
}
(main as any).$fid = 517;