tobogganSe connecter

packages

The Louise packages, each released on its own

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

55 lignes · 1886 octetsBrut · Historique
1/// Parts of a page that render on their own (ADR 0066): a page calls
2/// `later skeleton render` where a slow part goes, and the handler the
3/// application installs decides how parts render. `inline` renders them
4/// in place; `streamed` renders each in an actor of its own and streams it
5/// in as it finishes (`parts`).
6///
7/// `e` is the effects a part may perform. A part receives their handlers
8/// (its row is row evidence, ADR 0066) instead of capturing the page's, so
9/// it can run in an actor, under handlers installed there.
10
11import parts.{type Settings}
12import std/html.{type Html}
13import std/http.{type Response}
14import std/process.{type proc}
15import std/random.{type random}
16import std/time.{type clock}
17
18pub effect async<e>
19{
20 /// `skeleton` now, and `render`'s result once it is ready.
21 fn later :: skeleton: Html render: send fn() -> Html / <e> -> Html
22}
23
24/// Every part rendered in place, with the handlers around the page:
25/// for fragments, requests without a body, and tests.
26pub fn inline :: action: fn() -> a / <async<e> | e> -> a / <e>
27{
28 handle
29 {
30 action ()
31 }
32 with
33 { later _ render -> render () }
34}
35
36/// Every part rendered by an actor of its own, and the page streamed
37/// (`parts.respond`). `within` runs a part in its actor under the
38/// application's handlers; it is written as a lambda that calls the part:
39/// `fn render { within_app fn { render () } }`. `settings.nonce` is the
40/// request's: the streamed page's policy and swap script carry it.
41pub fn streamed ::
42 settings: Settings
43 action: fn() -> Response / <async<e> | e2>
44 within: send fn(fn() -> Html / <e>) -> Html / <proc, clock, random, io, ffi>
45 -> Response / <proc, random | e2>
46{
47 let held = parts.new ()
48 let resp = handle
49 {
50 action ()
51 }
52 with
53 { later skeleton render -> parts.start held skeleton fn { within render } }
54 parts.respond held settings resp
55}