@@ -17,7 +17,7 @@ Supported functionality:
17
17
* Timer functionality (` sleep ` , ` tick ` )
18
18
* File functionality (` read ` , ` write ` , ` mkdir ` , ` unlink ` , ...)
19
19
* A libcurl integration, allowing e.g. HTTP(S) downloads.
20
- * A libpqxx integration, for easy asynchronous interaction with PostgreSQL databases.
20
+ * A libpqxx integration, for asynchronous interaction with PostgreSQL databases.
21
21
* A threadpool for synchronous or CPU-bound tasks
22
22
* A ` SelectSet ` for polling multiple promises at once
23
23
@@ -29,13 +29,11 @@ underlying coroutine to run.
29
29
Where I/O or other activity causes a coroutine to be resumed, the coroutine will typically be run by
30
30
the scheduler, which you don't need to care about. Depending on the ` RunMode ` , pending coroutines
31
31
are either run once per event loop turn, or immediately from the libuv callback (` Immediate ` ). By
32
- default, they are run all at once in every event loop turn (` Deferred ` ).
32
+ default, they are run all at once in every event loop turn (` Deferred ` ). While you can set the run
33
+ mode for I/O events in ` uvco::runMain() ` (` Deferred ` vs. ` Immediate ` ), the externally visible
34
+ behavior should be the same, and code will work in both modes. If it doesn't: that's a bug in uvco.
33
35
34
- However, as a user you shouldn't have to care about this. While you can set the run mode for
35
- I/O events in ` uvco::runMain() ` (` Deferred ` vs. ` Immediate ` ), the externally visible behavior should
36
- be the same, and code will work in both modes. If it doesn't: that's a bug in uvco.
37
-
38
- Some types - like buffers received by sockets - use simple types like strings, which are easy to
36
+ Some types - like buffers filled by sockets - use simple types like strings, which are easy to
39
37
handle but not super efficient. This may need to be generalized.
40
38
41
39
## Goal
@@ -44,15 +42,17 @@ Provide ergonomic asynchronous abstractions of all libuv functionality, at satis
44
42
45
43
## Examples
46
44
47
- To run a coroutine, you need to set up an event loop. This is done by calling
48
- ` uvco::runMain ` with a lambda that returns a ` uvco::Promise<T> ` . ` runMain() ` either
49
- returns the resulting value after the event loop has finished, or throws an exception if
50
- a coroutine threw one.
45
+ To run a coroutine, you need to set up an event loop. This is done by calling ` uvco::runMain ` with a
46
+ callable taking a single ` const Loop& ` argument and returns a ` uvco::Promise<T> ` . ` runMain() ` either
47
+ returns the resulting value after the event loop has finished, or throws an exception if a coroutine
48
+ threw one.
51
49
52
50
A ` Promise<T> ` is a coroutine promise, and can be awaited. It is the basic unit, and only
53
51
access to concurrency; there is no ` Task ` or such. Awaiting a promise will save the current
54
52
execution state, and resume it as soon as the promise is ready. Currently, promises cannot
55
- be cancelled.
53
+ be properly cancelled; however, suspended coroutines can be cancelled - although the coroutine
54
+ they're waiting on will still run to completion (that's the downside of not having a ` Task `
55
+ primitive).
56
56
57
57
When in doubt, refer to the examples in ` test/ ` ; they are actively maintained.
58
58
@@ -68,9 +68,11 @@ trigger coroutine resumption from the event loop, which is defined in `src/run.c
68
68
#include " run.h"
69
69
#include " promise/promise.h"
70
70
71
+ using namespace uvco ;
72
+
71
73
Promise<void > someAsynchronousFunction (const Loop& loop) {
72
74
fmt::print("Hello from someAsynchronousFunction\n");
73
- co_await loop. sleep(1000);
75
+ co_await sleep(loop, 1000);
74
76
fmt::print("Goodbye from someAsynchronousFunction\n");
75
77
}
76
78
@@ -80,7 +82,7 @@ void run_loop() {
80
82
// The ` loop ` mediates access to the event loop and is used by uvco's types.
81
83
// Create a "root" promise by calling a coroutine, e.g. one that
82
84
// sets up a server.
83
- uvco:: runMain<void >([ ] (const Loop& loop) -> uvco:: Promise<void > {
85
+ runMain<void >([ ] (const Loop& loop) -> Promise<void > {
84
86
co_await someAsynchronousFunction(loop);
85
87
});
86
88
}
0 commit comments