@@ -15,8 +15,7 @@ Eio replaces existing concurrency libraries such as Lwt
15
15
<!-- vim-markdown-toc GFM -->
16
16
17
17
* [ Motivation] ( #motivation )
18
- * [ Current Status] ( #current-status )
19
- * [ Structure of the Code] ( #structure-of-the-code )
18
+ * [ Eio packages] ( #eio-packages )
20
19
* [ Getting OCaml 5.1] ( #getting-ocaml-51 )
21
20
* [ Getting Eio] ( #getting-eio )
22
21
* [ Running Eio] ( #running-eio )
@@ -80,22 +79,18 @@ Additionally, modern operating systems provide high-performance alternatives to
80
79
For example, Linux's io_uring system has applications write the operations they want to perform to a ring buffer,
81
80
which Linux handles asynchronously, and Eio can take advantage of this.
82
81
83
- ## Current Status
84
-
85
- See [ Eio 1.0 progress tracking] ( https://github.com/ocaml-multicore/eio/issues/388 ) for the current status.
86
82
Please try porting your programs to use Eio and submit PRs or open issues when you find problems.
87
83
Remember that you can always [ fall back to using Lwt libraries] ( #lwt ) to provide missing features if necessary.
88
-
89
84
See [ Awesome Multicore OCaml] [ ] for links to work migrating other projects to Eio.
90
85
91
- ## Structure of the Code
86
+ ## Eio packages
92
87
93
88
- [ Eio] [ ] provides concurrency primitives (promises, etc.) and a high-level, cross-platform OS API.
94
89
- [ Eio_posix] [ ] provides a cross-platform backend for these APIs for POSIX-type systems.
95
- - [ Eio_linux] [ ] provides a Linux io-uring backend for these APIs,
96
- plus a low-level API that can be used directly (in non-portable code).
90
+ - [ Eio_linux] [ ] provides a Linux io_uring backend for these APIs.
97
91
- [ Eio_windows] [ ] is for use on Windows (incomplete - [ help wanted] ( https://github.com/ocaml-multicore/eio/issues/125 ) ).
98
92
- [ Eio_main] [ ] selects an appropriate backend (e.g. ` eio_linux ` or ` eio_posix ` ), depending on your platform.
93
+ - [ Eio_js] [ ] allows Eio code to run in the browser, using ` js_of_ocaml ` .
99
94
100
95
## Getting OCaml 5.1
101
96
@@ -135,18 +130,18 @@ prompt and return after each line.)
135
130
# open Eio.Std;;
136
131
```
137
132
138
- This function writes a greeting to ` stdout ` using [ Eio.Flow] [ ] :
133
+ This function writes a greeting to ` out ` using [ Eio.Flow] [ ] :
139
134
140
135
``` ocaml
141
- let main ~stdout =
142
- Eio.Flow.copy_string "Hello, world!\n" stdout
136
+ let main out =
137
+ Eio.Flow.copy_string "Hello, world!\n" out
143
138
```
144
139
145
140
We use [ Eio_main.run] [ ] to run the event loop and call ` main ` from there:
146
141
147
142
``` ocaml
148
143
# Eio_main.run @@ fun env ->
149
- main ~stdout: (Eio.Stdenv.stdout env);;
144
+ main (Eio.Stdenv.stdout env);;
150
145
Hello, world!
151
146
- : unit = ()
152
147
```
@@ -156,7 +151,7 @@ Note that:
156
151
- The ` env ` argument represents the standard environment of a Unix process, allowing it to interact with the outside world.
157
152
A program will typically start by extracting from ` env ` whatever things the program will need and then calling ` main ` with them.
158
153
159
- - The type of the ` main ` function here tells us that this program only interacts via ` stdout ` .
154
+ - The type of the ` main ` function here tells us that this program only interacts via the ` out ` flow .
160
155
161
156
- ` Eio_main.run ` automatically calls the appropriate run function for your platform.
162
157
For example, on Linux this will call ` Eio_linux.run ` . For non-portable code you can use the platform-specific library directly.
@@ -171,7 +166,7 @@ For example, instead of giving `main` the real standard output, we can have it w
171
166
``` ocaml
172
167
# Eio_main.run @@ fun _env ->
173
168
let buffer = Buffer.create 20 in
174
- main ~stdout: (Eio.Flow.buffer_sink buffer);
169
+ main (Eio.Flow.buffer_sink buffer);
175
170
traceln "Main would print %S" (Buffer.contents buffer);;
176
171
+Main would print "Hello, world!\n"
177
172
- : unit = ()
@@ -185,8 +180,7 @@ The [Eio_mock][] library provides some convenient pre-built mocks:
185
180
``` ocaml
186
181
# #require "eio.mock";;
187
182
# Eio_main.run @@ fun _env ->
188
- let mock_stdout = Eio_mock.Flow.make "mock-stdout" in
189
- main ~stdout:mock_stdout;;
183
+ main (Eio_mock.Flow.make "mock-stdout");;
190
184
+mock-stdout: wrote "Hello, world!\n"
191
185
- : unit = ()
192
186
```
@@ -934,6 +928,9 @@ The mock backend provides a mock clock that advances automatically where there i
934
928
- : unit = ()
935
929
```
936
930
931
+ Note: You could also just use ` Eio_unix.sleep 5.0 ` if you don't want to pass a clock around.
932
+ This is especially useful if you need to insert a delay for some quick debugging.
933
+
937
934
## Multicore Support
938
935
939
936
OCaml allows a program to create multiple * domains* in which to run code, allowing multiple CPUs to be used at once.
@@ -1593,6 +1590,9 @@ In particular, if you test your code by providing (deterministic) mocks then the
1593
1590
An easy way to write tests is by having the mocks call ` traceln ` and then comparing the trace output with the expected output.
1594
1591
See Eio's own tests for examples, e.g., [ tests/switch.md] ( tests/switch.md ) .
1595
1592
1593
+ Note: this only applies to the high-level APIs in the ` Eio ` module.
1594
+ Programs can behave non-deterministically when using ` Eio_unix ` or the various ` Low_level ` APIs provided by the backends.
1595
+
1596
1596
## Provider Interfaces
1597
1597
1598
1598
Eio applications use resources by calling functions (such as ` Eio.Flow.write ` ).
@@ -1912,3 +1912,4 @@ Some background about the effects system can be found in:
1912
1912
[ Olly ] : https://github.com/tarides/runtime_events_tools
1913
1913
[ eio-trace ] : https://github.com/ocaml-multicore/eio-trace
1914
1914
[ cap_enter ] : https://man.freebsd.org/cgi/man.cgi?query=cap_enter
1915
+ [ eio_js ] : https://github.com/ocaml-multicore/eio_js
0 commit comments