https://github.com/ocaml-multicore/eio_js
Eio for JavaScript environments
https://github.com/ocaml-multicore/eio_js
Last synced: 2 months ago
JSON representation
Eio for JavaScript environments
- Host: GitHub
- URL: https://github.com/ocaml-multicore/eio_js
- Owner: ocaml-multicore
- License: isc
- Created: 2024-02-06T13:21:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-01T17:06:25.000Z (11 months ago)
- Last Synced: 2025-04-30T22:08:27.753Z (2 months ago)
- Language: OCaml
- Size: 78.1 KB
- Stars: 10
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# eio_js - Eio for JavaScript environments
The following packages are provided:
- `js_of_ocaml-eio`, an Eio counterpart to package `js_of_ocaml-lwt`;
- `eio_brr`, a package providing Eio variants of Brr functions (which returns 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.
Here is a short example using `Eio_brr`.
```ocaml
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)
```