package eio_js_backend
Build not yet checked sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Simple Eio scheduler for JavaScript environments
Install
dune-project
Dependency
Authors
Maintainers
Sources
eio_js_backend-0.1.0.tbz
sha256=72ccf78096c361d6a85f0d854025a88bbf26b042b038d073b93e978dbb4b9a5c
sha512=83855e99a14659b43b65242890d5c134de40910ea70f6006517d09c30d65ed3c0ee398e03d47599644223ef3862bb4c0e484acbf961bbb2ce74636b2fffe2864
doc/README.html
eio_js - Eio for JavaScript environments
The following packages are provided:
js_of_ocaml-eio, an Eio counterpart to packagejs_of_ocaml-lwt;eio_brr, a package providing Eio variants of Brr functions (which return directly instead of returning a future);eio_js_backend, a common Eio JavaScript backend.
You can use Eio_brr.start or Js_of_ocaml_eio.Eio_js.start to execute a function asynchronously in a context where Eio operations can be performed.
Programs must be compiled with support for effect handlers:
- with
js_of_ocaml, pass--effects=cpsor--effects=double-translation; - with
wasm_of_ocaml, pass--effects=cps. The default,--effects=jspi, is not supported: JSPI cannot resume a fiber from a JavaScript callback.
For instance, with dune (the wasm mode needs (lang dune 3.17)):
(executable
(name main)
(modes js wasm)
(js_of_ocaml (flags --effects=cps))
(wasm_of_ocaml (flags --effects=cps))
(libraries eio_brr))Here is a short example using Eio_brr.
let counter = get_element "counter" in
let text = get_element "text" in
let output = get_element "output" in
Eio_brr.start @@ fun () ->
Fiber.both
(fun () ->
(* A little text editor *)
while true do
let ev = Eio_brr.Ev.next Ev.keyup (El.as_target text) in
let target = Jv.get (Ev.to_jv ev) "target" in
let text = Jv.get target "value" |> Jv.to_jstr in
El.set_children output [ El.txt text ]
done)
(fun () ->
(* A little timer counting up *)
let i = ref 0 in
while true do
El.set_children counter [ El.txt' (string_of_int !i ^ "s") ];
Eio_brr.G.set_timeout ~ms:1000;
incr i
done)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>